Skip to content
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
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();
});
Loading