Skip to content
Closed
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
17 changes: 15 additions & 2 deletions gui/tests/codex-account-pool-target-switch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,21 @@ async function switchTarget(targetKey: string, releasePrevious: () => void) {
configureApiTargets(relay("/same", targetKey));
actEnvironment(false);
try {
root!.render(<Probe targetKey={targetKey} onSwitch={releasePrevious} />);
await new Promise(resolve => setTimeout(resolve, 0));
// A timer scheduled before React commits can win the race on a loaded runner.
// Observe the layout commit itself; release the old read in that same phase so
// the regression still exercises the interval before passive effects run.
await new Promise<void>(resolve => {
root!.render(<Probe targetKey={targetKey} onSwitch={() => { releasePrevious(); resolve(); }} />);
});
// The new target's first read is kicked from a passive effect plus a queued
// microtask, so the layout commit alone cannot prove it started. Wait until the
// in-flight state is painted: `refreshing` turns true only after the read's
// fetch was issued and React committed the new counter. The timer is the yield
// between observations, not an assumption that effects have completed.
for (let spins = 0; seen?.refreshing !== true; spins += 1) {
if (spins >= 1000) throw new Error("the new target's read never reached in-flight state");
await new Promise(resolve => setTimeout(resolve, 0));
}
} finally {
actEnvironment(true);
}
Expand Down
Loading