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

Fix flaky ServerMetricsCollector integration test #65420

Merged
merged 2 commits into from
May 6, 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
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,22 @@ describe('ServerMetricsCollector', () => {
let metrics = await collector.collect();
expect(metrics.concurrent_connections).toEqual(0);

sendGet('/').end(() => null);
// supertest requests are executed when calling `.then` (or awaiting them).
// however in this test we need to send the request now and await for it later in the code.
// also using `.end` is not possible as it would execute the request twice.
// so the only option is this noop `.then`.
const res1 = sendGet('/').then(res => res);
await waitForHits(1);
metrics = await collector.collect();
expect(metrics.concurrent_connections).toEqual(1);

sendGet('/').end(() => null);
const res2 = sendGet('/').then(res => res);
await waitForHits(2);
metrics = await collector.collect();
expect(metrics.concurrent_connections).toEqual(2);

waitSubject.next('go');
await delay(requestWaitDelay);
await Promise.all([res1, res2]);
metrics = await collector.collect();
expect(metrics.concurrent_connections).toEqual(0);
});
Expand Down