Skip to content

Commit f8d3e61

Browse files
committed
fix(cli-build): wait for processing log before SIGTERM in wait test
The 'stops waiting on process termination' test used a fixed 100 ms setTimeout before emitting SIGTERM, racing the first poll's log emit on slow Windows runners. Two coupled failure modes were observed: A. The 'Processing 18 snapshots - 0 of 72 comparisons finished...' log hadn't landed yet, so logger.stdout was empty and the assertion got `Expected $.length = 0 to equal 1`. B. The same log arrived a few ms later and bled into the *next* test's logger snapshot ('failure messages > logs an error when there are no snapshots'), tripping `Expected $.length = 1 to equal 0` there. Replace the fixed wait with a poll-until-logged loop bounded by a 5s deadline. Once the expected log line is observed, SIGTERM and assertion proceed deterministically — no race, no bleed. Eliminates the ~6 retry events observed across PRs #2147, #2172, #2177 on Test @percy/cli-build Windows jobs.
1 parent 751a0e3 commit f8d3e61

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

packages/cli-build/test/wait.test.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,26 @@ describe('percy build:wait', () => {
213213

214214
let waiting = wait(['--build=123']);
215215

216-
// wait a moment before terminating
217-
await new Promise(r => setTimeout(r, 100));
216+
// Wait for the first poll to actually log its progress before
217+
// emitting SIGTERM. A fixed setTimeout was racing the poll on slow
218+
// Windows runners — the log would land *after* the test snapshotted
219+
// logger.stdout (failure mode A) or bleed into the next test's
220+
// logger snapshot (failure mode B).
221+
let expected = '[percy] Processing 18 snapshots - 0 of 72 comparisons finished...';
222+
let deadline = Date.now() + 5000;
223+
while (!logger.stdout.includes(expected)) {
224+
if (Date.now() >= deadline) {
225+
throw new Error(`timed out waiting for processing log; saw: ${JSON.stringify(logger.stdout)}`);
226+
}
227+
await new Promise(r => setTimeout(r, 25));
228+
}
218229
await expectAsync(waiting).toBePending();
219230

220231
process.emit('SIGTERM');
221232
await waiting;
222233

223234
expect(logger.stderr).toEqual([]);
224-
expect(logger.stdout).toEqual([
225-
'[percy] Processing 18 snapshots - 0 of 72 comparisons finished...'
226-
]);
235+
expect(logger.stdout).toEqual([expected]);
227236
});
228237

229238
describe('failure messages', () => {

0 commit comments

Comments
 (0)