Skip to content

Commit 94414a1

Browse files
authored
fix(auto-instrumentations-node): make SIGTERM shutdown test more reliable (#2667)
1 parent 3e95995 commit 94414a1

File tree

1 file changed

+22
-10
lines changed
  • metapackages/auto-instrumentations-node/test/test-app

1 file changed

+22
-10
lines changed

metapackages/auto-instrumentations-node/test/test-app/app-server.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,34 @@
1717
//Used in register.test.ts to mimic a JS app that stays alive like a server.
1818
const http = require('http');
1919

20-
const options = {
21-
hostname: 'example.com',
22-
port: 80,
23-
path: '/',
24-
method: 'GET',
25-
};
20+
// Create a local server that responds immediately
21+
const server = http.createServer((req, res) => {
22+
res.end('ok');
23+
});
24+
25+
server.listen(0, () => {
26+
const port = server.address().port;
27+
const req = http.request({
28+
hostname: 'localhost',
29+
port: port,
30+
path: '/',
31+
method: 'GET',
32+
});
2633

27-
const req = http.request(options);
28-
req.end();
29-
req.on('close', () => {
30-
console.log('Finished request');
34+
req.end();
35+
req.on('response', res => {
36+
res.on('end', () => {
37+
console.log('Finished request');
38+
});
39+
res.resume();
40+
});
3141
});
3242

3343
// Make sure there is work on the event loop
3444
const handle = setInterval(() => {}, 1);
45+
3546
// Gracefully shut down
3647
process.on('SIGTERM', () => {
3748
clearInterval(handle);
49+
server.close();
3850
});

0 commit comments

Comments
 (0)