Skip to content

Commit

Permalink
fix(auto-instrumentations-node): make SIGTERM shutdown test more reli…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
garysassano committed Jan 17, 2025
1 parent 4cf7e6f commit cbe2117
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions metapackages/auto-instrumentations-node/test/test-app/app-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('Finished 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();
});

0 comments on commit cbe2117

Please sign in to comment.