diff --git a/test/parallel/test-http-set-timeout-server.js b/test/parallel/test-http-set-timeout-server.js index b2b15d4838d1c0..8c16ac922186bb 100644 --- a/test/parallel/test-http-set-timeout-server.js +++ b/test/parallel/test-http-set-timeout-server.js @@ -21,22 +21,24 @@ function run() { } test(function serverTimeout(cb) { - const server = http.createServer(function(req, res) { + const server = http.createServer(common.mustCall(function(req, res) { // just do nothing, we should get a timeout event. - }); - server.listen(common.mustCall(function() { - http.get({ port: server.address().port }).on('error', common.mustCall()); })); - const s = server.setTimeout(50, common.mustCall(function(socket) { - socket.destroy(); - server.close(); - cb(); + server.listen(common.mustCall(function() { + const s = server.setTimeout(50, common.mustCall(function(socket) { + socket.destroy(); + server.close(); + cb(); + })); + assert.ok(s instanceof http.Server); + http.get({ + port: server.address().port + }).on('error', common.mustCall()); })); - assert.ok(s instanceof http.Server); }); test(function serverRequestTimeout(cb) { - const server = http.createServer(function(req, res) { + const server = http.createServer(common.mustCall(function(req, res) { // just do nothing, we should get a timeout event. const s = req.setTimeout(50, common.mustCall(function(socket) { socket.destroy(); @@ -44,10 +46,12 @@ test(function serverRequestTimeout(cb) { cb(); })); assert.ok(s instanceof http.IncomingMessage); - }); + })); server.listen(common.mustCall(function() { - const port = server.address().port; - const req = http.request({ port: port, method: 'POST' }); + const req = http.request({ + port: server.address().port, + method: 'POST' + }); req.on('error', common.mustCall()); req.write('Hello'); // req is in progress @@ -55,7 +59,7 @@ test(function serverRequestTimeout(cb) { }); test(function serverResponseTimeout(cb) { - const server = http.createServer(function(req, res) { + const server = http.createServer(common.mustCall(function(req, res) { // just do nothing, we should get a timeout event. const s = res.setTimeout(50, common.mustCall(function(socket) { socket.destroy(); @@ -63,28 +67,30 @@ test(function serverResponseTimeout(cb) { cb(); })); assert.ok(s instanceof http.OutgoingMessage); - }); + })); server.listen(common.mustCall(function() { - const port = server.address().port; - http.get({ port: port }).on('error', common.mustCall()); + http.get({ + port: server.address().port + }).on('error', common.mustCall()); })); }); test(function serverRequestNotTimeoutAfterEnd(cb) { - const server = http.createServer(function(req, res) { + const server = http.createServer(common.mustCall(function(req, res) { // just do nothing, we should get a timeout event. const s = req.setTimeout(50, common.mustNotCall()); assert.ok(s instanceof http.IncomingMessage); res.on('timeout', common.mustCall()); - }); - server.on('timeout', function(socket) { + })); + server.on('timeout', common.mustCall(function(socket) { socket.destroy(); server.close(); cb(); - }); + })); server.listen(common.mustCall(function() { - const port = server.address().port; - http.get({ port: port }).on('error', common.mustCall()); + http.get({ + port: server.address().port + }).on('error', common.mustCall()); })); }); @@ -103,16 +109,19 @@ test(function serverResponseTimeoutWithPipeline(cb) { assert.ok(s instanceof http.OutgoingMessage); if (req.url === '/1') res.end(); }); - server.on('timeout', function(socket) { + server.on('timeout', common.mustCall(function(socket) { if (secReceived) { socket.destroy(); server.close(); cb(); } - }); + })); server.listen(common.mustCall(function() { - const port = server.address().port; - const c = net.connect({ port: port, allowHalfOpen: true }, function() { + const options = { + port: server.address().port, + allowHalfOpen: true, + }; + const c = net.connect(options, function() { c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n'); c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n'); c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n'); @@ -121,11 +130,11 @@ test(function serverResponseTimeoutWithPipeline(cb) { }); test(function idleTimeout(cb) { - const server = http.createServer(function(req, res) { + const server = http.createServer(common.mustCall(function(req, res) { req.on('timeout', common.mustNotCall()); res.on('timeout', common.mustNotCall()); res.end(); - }); + })); const s = server.setTimeout(50, common.mustCall(function(socket) { socket.destroy(); server.close(); @@ -133,8 +142,11 @@ test(function idleTimeout(cb) { })); assert.ok(s instanceof http.Server); server.listen(common.mustCall(function() { - const port = server.address().port; - const c = net.connect({ port: port, allowHalfOpen: true }, function() { + const options = { + port: server.address().port, + allowHalfOpen: true, + }; + const c = net.connect(options, function() { c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n'); // Keep-Alive }); diff --git a/test/sequential/test-https-set-timeout-server.js b/test/sequential/test-https-set-timeout-server.js index a2da563464352f..a9467877d09a14 100644 --- a/test/sequential/test-https-set-timeout-server.js +++ b/test/sequential/test-https-set-timeout-server.js @@ -6,7 +6,9 @@ if (!common.hasCrypto) { common.skip('missing crypto'); return; } + const https = require('https'); +const http = require('http'); const tls = require('tls'); const fs = require('fs'); @@ -35,10 +37,13 @@ function run() { } test(function serverTimeout(cb) { - const server = https.createServer(serverOptions, function(req, res) { - // just do nothing, we should get a timeout event. - }); - server.listen(0, common.mustCall(function() { + const server = https.createServer( + serverOptions, + common.mustCall(function(req, res) { + // just do nothing, we should get a + // timeout event. + })); + server.listen(common.mustCall(function() { const s = server.setTimeout(50, common.mustCall(function(socket) { socket.destroy(); server.close(); @@ -46,72 +51,79 @@ test(function serverTimeout(cb) { })); assert.ok(s instanceof https.Server); https.get({ - port: this.address().port, + port: server.address().port, rejectUnauthorized: false }).on('error', common.noop); })); }); test(function serverRequestTimeout(cb) { - function handler(req, res) { - // just do nothing, we should get a timeout event. - req.setTimeout(50, common.mustCall(function() { - req.socket.destroy(); - server.close(); - cb(); + const server = https.createServer( + serverOptions, + common.mustCall(function(req, res) { + // just do nothing, we should get a + // timeout event. + const s = req.setTimeout( + 50, + common.mustCall(function(socket) { + socket.destroy(); + server.close(); + cb(); + })); + assert.ok(s instanceof http.IncomingMessage); })); - } - - let server = https.createServer(serverOptions, common.mustCall(handler)); - server.listen(0, function() { + server.listen(common.mustCall(function() { const req = https.request({ - port: this.address().port, + port: server.address().port, method: 'POST', rejectUnauthorized: false }); req.on('error', common.noop); req.write('Hello'); // req is in progress - }); + })); }); test(function serverResponseTimeout(cb) { - function handler(req, res) { - // just do nothing, we should get a timeout event. - res.setTimeout(50, common.mustCall(function() { - res.socket.destroy(); - server.close(); - cb(); + const server = https.createServer( + serverOptions, + common.mustCall(function(req, res) { + // just do nothing, we should get a timeout event. + const s = res.setTimeout(50, common.mustCall(function(socket) { + socket.destroy(); + server.close(); + cb(); + })); + assert.ok(s instanceof http.OutgoingMessage); })); - } - - let server = https.createServer(serverOptions, common.mustCall(handler)); - server.listen(0, function() { + server.listen(common.mustCall(function() { https.get({ - port: this.address().port, + port: server.address().port, rejectUnauthorized: false - }).on('error', common.noop); - }); + }).on('error', common.mustCall()); + })); }); test(function serverRequestNotTimeoutAfterEnd(cb) { - function handler(req, res) { - // just do nothing, we should get a timeout event. - req.setTimeout(50, common.mustNotCall()); - res.on('timeout', common.mustCall(function(socket) {})); - } - const server = https.createServer(serverOptions, common.mustCall(handler)); - server.on('timeout', function(socket) { + const server = https.createServer( + serverOptions, + common.mustCall(function(req, res) { + // just do nothing, we should get a timeout event. + const s = req.setTimeout(50, common.mustNotCall()); + assert.ok(s instanceof http.IncomingMessage); + res.on('timeout', common.mustCall()); + })); + server.on('timeout', common.mustCall(function(socket) { socket.destroy(); server.close(); cb(); - }); - server.listen(0, function() { + })); + server.listen(common.mustCall(function() { https.get({ - port: this.address().port, + port: server.address().port, rejectUnauthorized: false - }).on('error', common.noop); - }); + }).on('error', common.mustCall()); + })); }); test(function serverResponseTimeoutWithPipeline(cb) { @@ -123,9 +135,10 @@ test(function serverResponseTimeoutWithPipeline(cb) { const server = https.createServer(serverOptions, function(req, res) { if (req.url === '/2') secReceived = true; - res.setTimeout(50, function() { + const s = res.setTimeout(50, function() { caughtTimeout += req.url; }); + assert.ok(s instanceof http.OutgoingMessage); if (req.url === '/1') res.end(); }); server.on('timeout', function(socket) { @@ -135,9 +148,9 @@ test(function serverResponseTimeoutWithPipeline(cb) { cb(); } }); - server.listen(0, function() { + server.listen(common.mustCall(function() { const options = { - port: this.address().port, + port: server.address().port, allowHalfOpen: true, rejectUnauthorized: false }; @@ -146,24 +159,26 @@ test(function serverResponseTimeoutWithPipeline(cb) { c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n'); c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n'); }); - }); + })); }); test(function idleTimeout(cb) { - const server = https.createServer(serverOptions, - common.mustCall(function(req, res) { - req.on('timeout', common.mustNotCall()); - res.on('timeout', common.mustNotCall()); - res.end(); - })); - server.setTimeout(50, common.mustCall(function(socket) { + const server = https.createServer( + serverOptions, + common.mustCall(function(req, res) { + req.on('timeout', common.mustNotCall()); + res.on('timeout', common.mustNotCall()); + res.end(); + })); + const s = server.setTimeout(50, common.mustCall(function(socket) { socket.destroy(); server.close(); cb(); })); - server.listen(0, function() { + assert.ok(s instanceof https.Server); + server.listen(common.mustCall(function() { const options = { - port: this.address().port, + port: server.address().port, allowHalfOpen: true, rejectUnauthorized: false }; @@ -171,5 +186,5 @@ test(function idleTimeout(cb) { this.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n'); // Keep-Alive }); - }); + })); });