Skip to content

Commit

Permalink
[7.8] Fix flaky ServerMetricsCollector integration test (elastic#65420)…
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer authored May 14, 2020
1 parent 0e21bed commit d78d816
Showing 1 changed file with 7 additions and 3 deletions.
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

0 comments on commit d78d816

Please sign in to comment.