Skip to content

Commit ee72a69

Browse files
committed
test(session): de-flake SessionProvider normal-load test
flush() only drained microtasks, so the query->render update occasionally lost the race and ctx.data was still null after the flush budget. Yield one macrotask tick per flush so React Query's notifyManager and deferred renders settle deterministically. Verified across repeated local runs.
1 parent 2ff83bc commit ee72a69

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

apps/sim/app/_shell/providers/session-provider.test.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,18 @@ function renderProvider(): Harness {
107107
}
108108
}
109109

110-
/** Flush pending microtasks inside an act() boundary. */
110+
/**
111+
* Flush pending work inside an act() boundary. Drains the microtask queue and
112+
* then yields one macrotask tick, so React Query's notifyManager (which can
113+
* schedule observer notifications on a timer) and any deferred renders settle
114+
* deterministically — microtask-only flushing raced the query→render update.
115+
*/
111116
async function flush() {
112117
await act(async () => {
113118
await Promise.resolve()
114119
await Promise.resolve()
115120
await Promise.resolve()
121+
await new Promise<void>((resolve) => setTimeout(resolve, 0))
116122
})
117123
}
118124

0 commit comments

Comments
 (0)