@@ -489,7 +489,7 @@ def add_item(i):
489489 self .assertEqual (bag_states ['key' + str (i )].items , [])
490490
491491 @staticmethod
492- def _run_reset_state_deadlock_scenario (use_asyncio ):
492+ def _run_reset_state_concurrent_teardown (use_asyncio ):
493493 dofn = BasicDofn (sleep_time = 0.5 )
494494 async_dofn = async_lib .AsyncWrapper (dofn , use_asyncio = use_asyncio )
495495 async_dofn .setup ()
@@ -500,16 +500,15 @@ def _run_reset_state_deadlock_scenario(use_asyncio):
500500 async_dofn .process (('key1' , 1 ), to_process = fake_bag_state , timer = fake_timer )
501501 time .sleep (0.05 )
502502
503- # Attempt to call reset_state(). If the fix is NOT applied, this will deadlock
504- # forever because reset_state() holds the lock while waiting for active tasks/threads,
505- # blocking the future's done callback from acquiring the lock.
503+ # Verify that calling reset_state() while background tasks are actively running
504+ # completes cleanly without causing lock-ordering deadlocks.
506505 async_lib .AsyncWrapper .reset_state ()
507506
508- def test_reset_state_hang_reproduction (self ):
509- # Run the deadlock scenario in a separate process so that if it hangs,
510- # we can terminate it without causing the main pytest process to hang at exit.
507+ def test_reset_state_concurrent_teardown (self ):
508+ # Verify concurrent teardown safety in a separate process to prevent any potential
509+ # regressions from freezing the main pytest process at exit.
511510 p = multiprocessing .Process (
512- target = AsyncTest ._run_reset_state_deadlock_scenario ,
511+ target = AsyncTest ._run_reset_state_concurrent_teardown ,
513512 args = (self .use_asyncio , ))
514513 p .start ()
515514 p .join (timeout = 10.0 )
0 commit comments