Skip to content

Commit

Permalink
Merge pull request #1533 from snyk/test/fixMetricTest
Browse files Browse the repository at this point in the history
test: Fix a flaky test
  • Loading branch information
michael-c-snyk authored Nov 20, 2020
2 parents ef20c2c + ebe95cb commit e95484f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions test/metrics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ describe('TimerMetricInstance', () => {
expect(tmi.getValue()).toBeUndefined;
});

it('can time things', async () => {
it('can time things with sufficient accuracy', async () => {
const tmi = new TimerMetricInstance('timer/network_time');
tmi.start();
await sleep(10);
tmi.stop();
expect(tmi.getValue()).toBeGreaterThan(9);
// Sleep() is backed by setTimeout(), and some Node runtimes might execute setTimeout callback before the specified
// delay, meaning that tmi.getValue() will occasionally return `9` at this point. An extra ms leeway in this
// assertion works round the issue. https://github.com/nodejs/node/issues/10154
expect(tmi.getValue()).toBeGreaterThanOrEqual(9);
});

it('.start() / .stop() logs start/top and improper use warnings if you try to start/stop it again after stopping it', async () => {
Expand Down

0 comments on commit e95484f

Please sign in to comment.