okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
8d97901
main
1"""Stopped turns and deleted sessions release their daemon-wide running marks.""" 2 3import json 4import threading 5import unittest 6 7from harness import Albedo ,Provider ,ROOT ,exclusive ,text ,wait_until 8from inspect_support import Inspection 9 10 11class RunningMarksTest (unittest .TestCase ): 12# exclusive: enables inspection at daemon startup 13@exclusive 14def test_completed_closed_and_deleted_sessions_release_running_marks (self ): 15ready ,release = threading .Event (),threading .Event () 16self .addCleanup (release .set ) 17 18def script (_request ): 19ready .set () 20if not release .wait (30 ): 21raise AssertionError ("test did not release the provider" ) 22return text ("finished" ) 23 24provider = Provider (script ) 25self .addCleanup (provider .close ) 26with Albedo ( 27provider , 28prepare = lambda app :app .daemon .env .update (ALBEDO_INSPECT = "1" ), 29 )as app : 30inspection = Inspection (app ,ROOT / "test/e2e/albedo_running_probe.erl" ) 31for ending in ("completed" ,"closed" ,"deleted" ): 32with self .subTest (ending = ending ): 33ready .clear () 34release .clear () 35session = app .session () 36arguments = f"[<< { json . dumps ( session ) } >>]" 37self .assertEqual ( 38inspection .call_json ("state" ,arguments ), 39 {"running" :False ,"records" :0 }, 40 ) 41app .prompt (session ,ending ).close () 42try : 43self .assertTrue (ready .wait (20 ),"provider was not reached" ) 44self .assertEqual ( 45inspection .call_json ("state" ,arguments ), 46 {"running" :True ,"records" :1 }, 47 ) 48if ending == "completed" : 49release .set () 50app .idle (session ) 51elif ending == "closed" : 52self .assertEqual ( 53inspection .call ("close" ,arguments ),"closed" 54 ) 55else : 56path = f"/sessions/ { session } ?view=configuration" 57with app .api (path )as response : 58configuration = json .load (response ) 59revision = response .headers ["ETag" ] 60path += ( 61"&scope=subtree&family_revision=" 62+ configuration ["family_revision" ] 63 ) 64app .api ( 65path ,method = "DELETE" ,headers = {"If-Match" :revision } 66 ).close () 67wait_until ( 68lambda : ( 69inspection .call_json ("state" ,arguments ) 70== {"running" :False ,"records" :0 } 71 ), 7210 , 73"stopped session retained its running mark" , 74 ) 75finally : 76release .set ()