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 1 commit
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,18 @@ describe('ServerMetricsCollector', () => {
let metrics = await collector.collect();
expect(metrics.concurrent_connections).toEqual(0);

sendGet('/').end(() => null);
const res1 = sendGet('/').then(res => res);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supertest API... The request is sent when calling/awaiting .then. I'm forced to noop-chain the promise to execute the request without awaiting it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How it's different from .end()? I noticed that in case of end(), it logs superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises. Does it send a request twice 🤦

Copy link
Contributor

@mshustov mshustov May 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a comment about the usage of such a sophisticated construction in the test?

Copy link
Contributor Author

@pgayvallet pgayvallet May 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it send a request twice

Yea...

const req = sendGet('/').end(() => null);
// later
await req;

Does send the request on each line... Imho having .then executing the request is a very bad decision from this lib, but that's how it works... Which is why I had to use this .then trick to be able to execute the request and still await for it later.

Will add a comment

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