From bcf0185b799cd3290ba912d97efc346128e1cace Mon Sep 17 00:00:00 2001 From: Gary Sassano <10464497+garysassano@users.noreply.github.com> Date: Fri, 17 Jan 2025 16:15:17 +0100 Subject: [PATCH] test --- .../test/register.test.ts | 2 +- .../test/test-app/app-server.js | 32 +++++++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/metapackages/auto-instrumentations-node/test/register.test.ts b/metapackages/auto-instrumentations-node/test/register.test.ts index 2f952541db..47917c854b 100644 --- a/metapackages/auto-instrumentations-node/test/register.test.ts +++ b/metapackages/auto-instrumentations-node/test/register.test.ts @@ -90,7 +90,7 @@ describe('Register', function () { it('shuts down the NodeSDK when SIGTERM is received', async () => { const runPromise = runWithRegister('./test-app/app-server.js'); const { child } = runPromise; - await waitForString(child.stdout!, 'Finshed request'); + await waitForString(child.stdout!, 'Finished request'); child.kill('SIGTERM'); const { stdout } = await runPromise; diff --git a/metapackages/auto-instrumentations-node/test/test-app/app-server.js b/metapackages/auto-instrumentations-node/test/test-app/app-server.js index 489b4dfb7a..61e12b089e 100644 --- a/metapackages/auto-instrumentations-node/test/test-app/app-server.js +++ b/metapackages/auto-instrumentations-node/test/test-app/app-server.js @@ -17,22 +17,34 @@ //Used in register.test.ts to mimic a JS app that stays alive like a server. const http = require('http'); -const options = { - hostname: 'example.com', - port: 80, - path: '/', - method: 'GET', -}; +// Create a local server that responds immediately +const server = http.createServer((req, res) => { + res.end('ok'); +}); + +server.listen(0, () => { + const port = server.address().port; + const req = http.request({ + hostname: 'localhost', + port: port, + path: '/', + method: 'GET', + }); -const req = http.request(options); -req.end(); -req.on('close', () => { - console.log('Finshed request'); + req.end(); + req.on('response', res => { + res.on('end', () => { + console.log('Finished request'); + }); + res.resume(); + }); }); // Make sure there is work on the event loop const handle = setInterval(() => {}, 1); + // Gracefully shut down process.on('SIGTERM', () => { clearInterval(handle); + server.close(); });