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

test(instr-undici): fix TAV failures with Node.js 14 and 16 #2111

Merged
merged 1 commit into from
Apr 18, 2024
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
30 changes: 25 additions & 5 deletions plugins/node/instrumentation-undici/test/undici.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ describe('UndiciInstrumentation `undici` tests', function () {
propagation.disable();
mockServer.mockListener(undefined);
mockServer.stop(done);

// Close kept-alive sockets. This can save a 4s keep-alive delay before the
// process exits.
(undici as any).getGlobalDispatcher().close();
});

beforeEach(function () {
Expand Down Expand Up @@ -216,11 +220,27 @@ describe('UndiciInstrumentation `undici` tests', function () {
};

const queryRequestUrl = `${protocol}://${hostname}:${mockServer.port}/?query=test`;
const firstQueryResponse = await undici.request(queryRequestUrl, {
headers,
// @ts-expect-error - method type expects in uppercase
method: 'get',
});
let firstQueryResponse;
try {
firstQueryResponse = await undici.request(queryRequestUrl, {
headers,
// @ts-expect-error - method type expects in uppercase
method: 'get',
});
} catch (err: any) {
// This request is using a bogus HTTP method `get`. If (a) using Node.js
// v14, v16, or early v18.x versions and (b) this request is re-using
// a socket (from an earlier keep-alive request in this test file),
// then Node.js will emit 'end' on the socket. Undici then throws
// `SocketError: other side closed`. Given this is only for old Node.js
// versions and for this rare case of using a bogus HTTP method, we will
// skip out of this test instead of attempting to fully understand it.
assert.strictEqual(err.message, 'other side closed');
this.skip();
}
if (!firstQueryResponse) {
return;
}
await consumeResponseBody(firstQueryResponse.body);

const secondQueryResponse = await undici.request(queryRequestUrl, {
Expand Down
Loading