Skip to content

Commit

Permalink
chore(tests): async await instead of setTimeout (#496)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmchase authored Feb 27, 2022
1 parent 98b7ad8 commit 721829c
Showing 1 changed file with 52 additions and 48 deletions.
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));
}

0 comments on commit 721829c

Please sign in to comment.