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

chore(tests): async await instead of setTimeout #496

Merged
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
100 changes: 52 additions & 48 deletions test/metrics/eventLoopLagTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,57 @@ describe('eventLoopLag', () => {
expect(await register.getMetricsAsJSON()).toHaveLength(0);
eventLoopLag();

setTimeout(async () => {
const metrics = await register.getMetricsAsJSON();
expect(metrics).toHaveLength(8);

expect(metrics[0].help).toEqual('Lag of event loop in seconds.');
expect(metrics[0].type).toEqual('gauge');
expect(metrics[0].name).toEqual('nodejs_eventloop_lag_seconds');

expect(metrics[1].help).toEqual('The minimum recorded event loop delay.');
expect(metrics[1].type).toEqual('gauge');
expect(metrics[1].name).toEqual('nodejs_eventloop_lag_min_seconds');

expect(metrics[2].help).toEqual('The maximum recorded event loop delay.');
expect(metrics[2].type).toEqual('gauge');
expect(metrics[2].name).toEqual('nodejs_eventloop_lag_max_seconds');

expect(metrics[3].help).toEqual(
'The mean of the recorded event loop delays.',
);
expect(metrics[3].type).toEqual('gauge');
expect(metrics[3].name).toEqual('nodejs_eventloop_lag_mean_seconds');

expect(metrics[4].help).toEqual(
'The standard deviation of the recorded event loop delays.',
);
expect(metrics[4].type).toEqual('gauge');
expect(metrics[4].name).toEqual('nodejs_eventloop_lag_stddev_seconds');

expect(metrics[5].help).toEqual(
'The 50th percentile of the recorded event loop delays.',
);
expect(metrics[5].type).toEqual('gauge');
expect(metrics[5].name).toEqual('nodejs_eventloop_lag_p50_seconds');

expect(metrics[6].help).toEqual(
'The 90th percentile of the recorded event loop delays.',
);
expect(metrics[6].type).toEqual('gauge');
expect(metrics[6].name).toEqual('nodejs_eventloop_lag_p90_seconds');

expect(metrics[7].help).toEqual(
'The 99th percentile of the recorded event loop delays.',
);
expect(metrics[7].type).toEqual('gauge');
expect(metrics[7].name).toEqual('nodejs_eventloop_lag_p99_seconds');

done();
}, 5);
await wait(5);

const metrics = await register.getMetricsAsJSON();
expect(metrics).toHaveLength(8);

expect(metrics[0].help).toEqual('Lag of event loop in seconds.');
expect(metrics[0].type).toEqual('gauge');
expect(metrics[0].name).toEqual('nodejs_eventloop_lag_seconds');

expect(metrics[1].help).toEqual('The minimum recorded event loop delay.');
expect(metrics[1].type).toEqual('gauge');
expect(metrics[1].name).toEqual('nodejs_eventloop_lag_min_seconds');

expect(metrics[2].help).toEqual('The maximum recorded event loop delay.');
expect(metrics[2].type).toEqual('gauge');
expect(metrics[2].name).toEqual('nodejs_eventloop_lag_max_seconds');

expect(metrics[3].help).toEqual(
'The mean of the recorded event loop delays.',
);
expect(metrics[3].type).toEqual('gauge');
expect(metrics[3].name).toEqual('nodejs_eventloop_lag_mean_seconds');

expect(metrics[4].help).toEqual(
'The standard deviation of the recorded event loop delays.',
);
expect(metrics[4].type).toEqual('gauge');
expect(metrics[4].name).toEqual('nodejs_eventloop_lag_stddev_seconds');

expect(metrics[5].help).toEqual(
'The 50th percentile of the recorded event loop delays.',
);
expect(metrics[5].type).toEqual('gauge');
expect(metrics[5].name).toEqual('nodejs_eventloop_lag_p50_seconds');

expect(metrics[6].help).toEqual(
'The 90th percentile of the recorded event loop delays.',
);
expect(metrics[6].type).toEqual('gauge');
expect(metrics[6].name).toEqual('nodejs_eventloop_lag_p90_seconds');

expect(metrics[7].help).toEqual(
'The 99th percentile of the recorded event loop delays.',
);
expect(metrics[7].type).toEqual('gauge');
expect(metrics[7].name).toEqual('nodejs_eventloop_lag_p99_seconds');

done();
});
});

async function wait(ms) {
await new Promise(resolve => setTimeout(resolve, ms));
}