Skip to content

Commit

Permalink
Merge branch 'main' into remove-xray-propagator
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc authored Apr 18, 2024
2 parents fb1acac + 3621e09 commit 4a9b70a
Showing 1 changed file with 25 additions and 5 deletions.
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

0 comments on commit 4a9b70a

Please sign in to comment.