Skip to content

Commit

Permalink
✅ Make test more deterministic
Browse files Browse the repository at this point in the history
Sometimes it can take more than half of a second for the server to shutdown when forcefully
terminating. Removing the arbitrary wait and making the test more deterministic should show if this
was a test timing issue, or if termination itself is flakey.
  • Loading branch information
wwilsman committed Feb 9, 2021
1 parent 4a534ee commit c1dc6f2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/cli-exec/test/start.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ describe('percy exec:start', () => {
).resolves.toBeDefined();

process.emit('SIGTERM');
// wait for event to be handled
await new Promise(r => setTimeout(r, 500));

await expect(
fetch('http://localhost:5338/percy/healthcheck', { timeout: 10 })
).rejects.toThrow();
// check a few times rather than wait on a timeout to be deterministic
await expect(function check(i = 0) {
return fetch('http://localhost:5338/percy/healthcheck', { timeout: 10 })
.then(r => i >= 10 ? r : new Promise((res, rej) => {
setTimeout(() => check(i++).then(res, rej), 100);
}))
}()).rejects.toThrow();
});

it('logs an error when percy is already running', async () => {
Expand Down

0 comments on commit c1dc6f2

Please sign in to comment.