Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions sdks/python/apache_beam/transforms/async_dofn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def add_item(i):
self.assertEqual(bag_states['key' + str(i)].items, [])

@staticmethod
def _run_reset_state_concurrent_teardown(use_asyncio):
def _run_reset_state_concurrent_teardown(use_asyncio, reset_started):
dofn = BasicDofn(sleep_time=0.5)
async_dofn = async_lib.AsyncWrapper(dofn, use_asyncio=use_asyncio)
async_dofn.setup()
Expand All @@ -502,15 +502,26 @@ def _run_reset_state_concurrent_teardown(use_asyncio):

# Verify that calling reset_state() while background tasks are actively running
# completes cleanly without causing lock-ordering deadlocks.
reset_started.set()
async_lib.AsyncWrapper.reset_state()

def test_reset_state_concurrent_teardown(self):
# Verify concurrent teardown safety in a separate process to prevent any potential
# regressions from freezing the main pytest process at exit.
reset_started = multiprocessing.Event()
p = multiprocessing.Process(
target=AsyncTest._run_reset_state_concurrent_teardown,
args=(self.use_asyncio, ))
args=(self.use_asyncio, reset_started))
p.start()

# Python 3.14 uses forkserver by default on POSIX. Wait for child startup
# before measuring reset_state() so import and process startup time cannot
# be mistaken for a teardown deadlock.
if not reset_started.wait(timeout=30.0):
p.terminate()
p.join()
self.fail("child process did not reach reset_state() before timeout")

p.join(timeout=10.0)

if p.is_alive():
Expand Down
Loading