Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Fix a flaky test #1533

Merged
merged 1 commit into from
Nov 20, 2020
Merged
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
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