Skip to content

Commit de50973

Browse files
committed
flaky test fix
1 parent cff251b commit de50973

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

packages/test/src/helpers-integration.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,16 @@ export function configurableHelpers<T>(
285285
};
286286
}
287287

288+
/**
289+
* Set the pause state of an activity and wait for the state to be reflected in the workflow description.
290+
*
291+
* This function handles a race condition where an activity might complete (due to catching a cancellation)
292+
* before we can verify that it's been paused. In that case, if the activity is no longer in pendingActivities
293+
* and we're trying to pause it, we consider the operation successful rather than timing out.
294+
*
295+
* This is particularly important for tests where the activity can complete immediately upon receiving a pause
296+
* cancellation.
297+
*/
288298
export async function setActivityPauseState(handle: WorkflowHandle, activityId: string, pause: boolean): Promise<void> {
289299
const desc = await handle.describe();
290300
const req = {
@@ -303,7 +313,14 @@ export async function setActivityPauseState(handle: WorkflowHandle, activityId:
303313
await waitUntil(async () => {
304314
const { raw } = await handle.describe();
305315
const activityInfo = raw.pendingActivities?.find((act) => act.activityId === activityId);
306-
if (!activityInfo) return false;
316+
317+
// If we're trying to pause and the activity is no longer in pendingActivities,
318+
// it might have completed due to catching the cancellation. Consider this a success.
319+
if (!activityInfo) {
320+
// Only consider this a success for pause operations, not unpause
321+
return pause;
322+
}
323+
307324
if (pause) {
308325
return activityInfo.paused ?? false;
309326
}

0 commit comments

Comments
 (0)