Skip to content

Commit fbeaeec

Browse files
brianstrauchclaude
andcommitted
Fix flaky pause_and_assert helper
When a paused activity catches the cancellation and returns (catch_err=True), it leaves the pending list before pause_and_assert can observe paused=true, causing AssertionError after timeout. Treat "no longer pending" as success since these test activities only stop running due to the cancellation we triggered. Also fix a latent bug where check_paused/check_unpaused returned bool to assert_eventually, which only retries on AssertionError — a False return would terminate immediately rather than poll until the state was observed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f6e113d commit fbeaeec

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

tests/helpers/__init__.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,15 @@ async def pause_and_assert(client: Client, handle: WorkflowHandle, activity_id:
278278
)
279279
await client.workflow_service.pause_activity(req)
280280

281-
# Assert eventually paused
282-
async def check_paused() -> bool:
283-
info = await assert_pending_activity_exists_eventually(handle, activity_id)
284-
return info.paused
281+
# Assert eventually paused. If the activity catches the pause-induced
282+
# cancellation and returns, it leaves the pending list before we poll —
283+
# treat that as success since these test activities only stop running
284+
# because of the cancellation we triggered.
285+
async def check_paused() -> None:
286+
info = await get_pending_activity_info(handle, activity_id)
287+
if info is None:
288+
return
289+
assert info.paused, f"Activity {activity_id} not yet paused"
285290

286291
await assert_eventually(check_paused)
287292

@@ -300,9 +305,9 @@ async def unpause_and_assert(client: Client, handle: WorkflowHandle, activity_id
300305
await client.workflow_service.unpause_activity(req)
301306

302307
# Assert eventually not paused
303-
async def check_unpaused() -> bool:
308+
async def check_unpaused() -> None:
304309
info = await assert_pending_activity_exists_eventually(handle, activity_id)
305-
return not info.paused
310+
assert not info.paused, f"Activity {activity_id} still paused"
306311

307312
await assert_eventually(check_unpaused)
308313

0 commit comments

Comments
 (0)