Skip to content

Commit 751a0e3

Browse files
committed
fix(cli-exec): poll healthcheck in 'can start on an alternate port' test
`start(['--port=4567'])` returns a Promise that resolves on process exit, not on listen — the test fired a single healthcheck immediately and got ECONNREFUSED on slow Windows runners before the alternate-port server had bound. Replace the single shot with a 5-second poll loop, mirroring the pattern already used in the 'stops the process when terminated' test. Eliminates the intermittent ECONNREFUSED 127.0.0.1:4567 observed on PR #2172 run 24120410492 (Test @percy/cli-exec, Windows).
1 parent c6a7fba commit 751a0e3

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

packages/cli-exec/test/start.test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,19 @@ describe('percy exec:start', () => {
7171

7272
it('can start on an alternate port', async () => {
7373
start(['--quiet', '--port=4567']);
74-
let response = await request('http://localhost:4567/percy/healthcheck');
74+
// `start(...)` resolves only when the percy process exits, not when the
75+
// server has bound to the port. Polling healthcheck instead of a single
76+
// shot avoids ECONNREFUSED on slow runners (notably windows-latest)
77+
// before the listener is up.
78+
let response = await (async function poll(deadline = Date.now() + 5000) {
79+
try {
80+
return await request('http://localhost:4567/percy/healthcheck');
81+
} catch (err) {
82+
if (Date.now() >= deadline) throw err;
83+
await new Promise(r => setTimeout(r, 100));
84+
return poll(deadline);
85+
}
86+
})();
7587
expect(response).toHaveProperty('success', true);
7688
});
7789

0 commit comments

Comments
 (0)