test: make http(s)-set-timeout-server more similar
Make test-http(s)-set-timeout-server tests more similar and resolve the following issues: * `test-https-set-timeout-server.js` was missing some `assert` statements, including with `http` module * Both files were missing some calls to `common.mustCall()` * Both files were calling `createServer()` in different ways PR-URL: https://github.com/nodejs/node/pull/13822 Refs: https://github.com/nodejs/node/issues/13588 Refs: https://github.com/nodejs/node/pull/13625 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
5fbbd25dc4
commit
2e5ce2bc2c
@ -42,22 +42,24 @@ function run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test(function serverTimeout(cb) {
|
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.
|
// just do nothing, we should get a timeout event.
|
||||||
});
|
|
||||||
server.listen(common.mustCall(function() {
|
|
||||||
http.get({ port: server.address().port }).on('error', common.mustCall());
|
|
||||||
}));
|
}));
|
||||||
|
server.listen(common.mustCall(function() {
|
||||||
const s = server.setTimeout(50, common.mustCall(function(socket) {
|
const s = server.setTimeout(50, common.mustCall(function(socket) {
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
server.close();
|
server.close();
|
||||||
cb();
|
cb();
|
||||||
}));
|
}));
|
||||||
assert.ok(s instanceof http.Server);
|
assert.ok(s instanceof http.Server);
|
||||||
|
http.get({
|
||||||
|
port: server.address().port
|
||||||
|
}).on('error', common.mustCall());
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
test(function serverRequestTimeout(cb) {
|
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.
|
// just do nothing, we should get a timeout event.
|
||||||
const s = req.setTimeout(50, common.mustCall(function(socket) {
|
const s = req.setTimeout(50, common.mustCall(function(socket) {
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
@ -65,10 +67,12 @@ test(function serverRequestTimeout(cb) {
|
|||||||
cb();
|
cb();
|
||||||
}));
|
}));
|
||||||
assert.ok(s instanceof http.IncomingMessage);
|
assert.ok(s instanceof http.IncomingMessage);
|
||||||
});
|
}));
|
||||||
server.listen(common.mustCall(function() {
|
server.listen(common.mustCall(function() {
|
||||||
const port = server.address().port;
|
const req = http.request({
|
||||||
const req = http.request({ port: port, method: 'POST' });
|
port: server.address().port,
|
||||||
|
method: 'POST'
|
||||||
|
});
|
||||||
req.on('error', common.mustCall());
|
req.on('error', common.mustCall());
|
||||||
req.write('Hello');
|
req.write('Hello');
|
||||||
// req is in progress
|
// req is in progress
|
||||||
@ -76,7 +80,7 @@ test(function serverRequestTimeout(cb) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test(function serverResponseTimeout(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.
|
// just do nothing, we should get a timeout event.
|
||||||
const s = res.setTimeout(50, common.mustCall(function(socket) {
|
const s = res.setTimeout(50, common.mustCall(function(socket) {
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
@ -84,28 +88,30 @@ test(function serverResponseTimeout(cb) {
|
|||||||
cb();
|
cb();
|
||||||
}));
|
}));
|
||||||
assert.ok(s instanceof http.OutgoingMessage);
|
assert.ok(s instanceof http.OutgoingMessage);
|
||||||
});
|
}));
|
||||||
server.listen(common.mustCall(function() {
|
server.listen(common.mustCall(function() {
|
||||||
const port = server.address().port;
|
http.get({
|
||||||
http.get({ port: port }).on('error', common.mustCall());
|
port: server.address().port
|
||||||
|
}).on('error', common.mustCall());
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
test(function serverRequestNotTimeoutAfterEnd(cb) {
|
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.
|
// just do nothing, we should get a timeout event.
|
||||||
const s = req.setTimeout(50, common.mustNotCall());
|
const s = req.setTimeout(50, common.mustNotCall());
|
||||||
assert.ok(s instanceof http.IncomingMessage);
|
assert.ok(s instanceof http.IncomingMessage);
|
||||||
res.on('timeout', common.mustCall());
|
res.on('timeout', common.mustCall());
|
||||||
});
|
}));
|
||||||
server.on('timeout', function(socket) {
|
server.on('timeout', common.mustCall(function(socket) {
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
server.close();
|
server.close();
|
||||||
cb();
|
cb();
|
||||||
});
|
}));
|
||||||
server.listen(common.mustCall(function() {
|
server.listen(common.mustCall(function() {
|
||||||
const port = server.address().port;
|
http.get({
|
||||||
http.get({ port: port }).on('error', common.mustCall());
|
port: server.address().port
|
||||||
|
}).on('error', common.mustCall());
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -124,16 +130,19 @@ test(function serverResponseTimeoutWithPipeline(cb) {
|
|||||||
assert.ok(s instanceof http.OutgoingMessage);
|
assert.ok(s instanceof http.OutgoingMessage);
|
||||||
if (req.url === '/1') res.end();
|
if (req.url === '/1') res.end();
|
||||||
});
|
});
|
||||||
server.on('timeout', function(socket) {
|
server.on('timeout', common.mustCall(function(socket) {
|
||||||
if (secReceived) {
|
if (secReceived) {
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
server.close();
|
server.close();
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
server.listen(common.mustCall(function() {
|
server.listen(common.mustCall(function() {
|
||||||
const port = server.address().port;
|
const options = {
|
||||||
const c = net.connect({ port: port, allowHalfOpen: true }, function() {
|
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 /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 /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');
|
c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n');
|
||||||
@ -142,11 +151,11 @@ test(function serverResponseTimeoutWithPipeline(cb) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test(function idleTimeout(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());
|
req.on('timeout', common.mustNotCall());
|
||||||
res.on('timeout', common.mustNotCall());
|
res.on('timeout', common.mustNotCall());
|
||||||
res.end();
|
res.end();
|
||||||
});
|
}));
|
||||||
const s = server.setTimeout(50, common.mustCall(function(socket) {
|
const s = server.setTimeout(50, common.mustCall(function(socket) {
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
server.close();
|
server.close();
|
||||||
@ -154,8 +163,11 @@ test(function idleTimeout(cb) {
|
|||||||
}));
|
}));
|
||||||
assert.ok(s instanceof http.Server);
|
assert.ok(s instanceof http.Server);
|
||||||
server.listen(common.mustCall(function() {
|
server.listen(common.mustCall(function() {
|
||||||
const port = server.address().port;
|
const options = {
|
||||||
const c = net.connect({ port: port, allowHalfOpen: true }, function() {
|
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 /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
|
||||||
// Keep-Alive
|
// Keep-Alive
|
||||||
});
|
});
|
||||||
|
@ -30,6 +30,7 @@ if (!common.hasCrypto) {
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
|
const http = require('http');
|
||||||
const tls = require('tls');
|
const tls = require('tls');
|
||||||
|
|
||||||
const tests = [];
|
const tests = [];
|
||||||
@ -56,10 +57,13 @@ function run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test(function serverTimeout(cb) {
|
test(function serverTimeout(cb) {
|
||||||
const server = https.createServer(serverOptions, function(req, res) {
|
const server = https.createServer(
|
||||||
// just do nothing, we should get a timeout event.
|
serverOptions,
|
||||||
});
|
common.mustCall(function(req, res) {
|
||||||
server.listen(0, common.mustCall(function() {
|
// just do nothing, we should get a
|
||||||
|
// timeout event.
|
||||||
|
}));
|
||||||
|
server.listen(common.mustCall(function() {
|
||||||
const s = server.setTimeout(50, common.mustCall(function(socket) {
|
const s = server.setTimeout(50, common.mustCall(function(socket) {
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
server.close();
|
server.close();
|
||||||
@ -67,72 +71,79 @@ test(function serverTimeout(cb) {
|
|||||||
}));
|
}));
|
||||||
assert.ok(s instanceof https.Server);
|
assert.ok(s instanceof https.Server);
|
||||||
https.get({
|
https.get({
|
||||||
port: this.address().port,
|
port: server.address().port,
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false
|
||||||
}).on('error', common.mustCall());
|
}).on('error', common.mustCall());
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
test(function serverRequestTimeout(cb) {
|
test(function serverRequestTimeout(cb) {
|
||||||
function handler(req, res) {
|
const server = https.createServer(
|
||||||
// just do nothing, we should get a timeout event.
|
serverOptions,
|
||||||
req.setTimeout(50, common.mustCall(function() {
|
common.mustCall(function(req, res) {
|
||||||
req.socket.destroy();
|
// just do nothing, we should get a
|
||||||
|
// timeout event.
|
||||||
|
const s = req.setTimeout(
|
||||||
|
50,
|
||||||
|
common.mustCall(function(socket) {
|
||||||
|
socket.destroy();
|
||||||
server.close();
|
server.close();
|
||||||
cb();
|
cb();
|
||||||
}));
|
}));
|
||||||
}
|
assert.ok(s instanceof http.IncomingMessage);
|
||||||
|
}));
|
||||||
const server = https.createServer(serverOptions, common.mustCall(handler));
|
server.listen(common.mustCall(function() {
|
||||||
server.listen(0, function() {
|
|
||||||
const req = https.request({
|
const req = https.request({
|
||||||
port: this.address().port,
|
port: server.address().port,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false
|
||||||
});
|
});
|
||||||
req.on('error', common.mustCall());
|
req.on('error', common.mustCall());
|
||||||
req.write('Hello');
|
req.write('Hello');
|
||||||
// req is in progress
|
// req is in progress
|
||||||
});
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
test(function serverResponseTimeout(cb) {
|
test(function serverResponseTimeout(cb) {
|
||||||
function handler(req, res) {
|
const server = https.createServer(
|
||||||
|
serverOptions,
|
||||||
|
common.mustCall(function(req, res) {
|
||||||
// just do nothing, we should get a timeout event.
|
// just do nothing, we should get a timeout event.
|
||||||
res.setTimeout(50, common.mustCall(function() {
|
const s = res.setTimeout(50, common.mustCall(function(socket) {
|
||||||
res.socket.destroy();
|
|
||||||
server.close();
|
|
||||||
cb();
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
const server = https.createServer(serverOptions, common.mustCall(handler));
|
|
||||||
server.listen(0, function() {
|
|
||||||
https.get({
|
|
||||||
port: this.address().port,
|
|
||||||
rejectUnauthorized: false
|
|
||||||
}).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());
|
|
||||||
}
|
|
||||||
const server = https.createServer(serverOptions, common.mustCall(handler));
|
|
||||||
server.on('timeout', function(socket) {
|
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
server.close();
|
server.close();
|
||||||
cb();
|
cb();
|
||||||
});
|
}));
|
||||||
server.listen(0, function() {
|
assert.ok(s instanceof http.OutgoingMessage);
|
||||||
|
}));
|
||||||
|
server.listen(common.mustCall(function() {
|
||||||
https.get({
|
https.get({
|
||||||
port: this.address().port,
|
port: server.address().port,
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false
|
||||||
}).on('error', common.mustCall());
|
}).on('error', common.mustCall());
|
||||||
});
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
test(function serverRequestNotTimeoutAfterEnd(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.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(common.mustCall(function() {
|
||||||
|
https.get({
|
||||||
|
port: server.address().port,
|
||||||
|
rejectUnauthorized: false
|
||||||
|
}).on('error', common.mustCall());
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
test(function serverResponseTimeoutWithPipeline(cb) {
|
test(function serverResponseTimeoutWithPipeline(cb) {
|
||||||
@ -144,9 +155,10 @@ test(function serverResponseTimeoutWithPipeline(cb) {
|
|||||||
const server = https.createServer(serverOptions, function(req, res) {
|
const server = https.createServer(serverOptions, function(req, res) {
|
||||||
if (req.url === '/2')
|
if (req.url === '/2')
|
||||||
secReceived = true;
|
secReceived = true;
|
||||||
res.setTimeout(50, function() {
|
const s = res.setTimeout(50, function() {
|
||||||
caughtTimeout += req.url;
|
caughtTimeout += req.url;
|
||||||
});
|
});
|
||||||
|
assert.ok(s instanceof http.OutgoingMessage);
|
||||||
if (req.url === '/1') res.end();
|
if (req.url === '/1') res.end();
|
||||||
});
|
});
|
||||||
server.on('timeout', function(socket) {
|
server.on('timeout', function(socket) {
|
||||||
@ -156,9 +168,9 @@ test(function serverResponseTimeoutWithPipeline(cb) {
|
|||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
server.listen(0, function() {
|
server.listen(common.mustCall(function() {
|
||||||
const options = {
|
const options = {
|
||||||
port: this.address().port,
|
port: server.address().port,
|
||||||
allowHalfOpen: true,
|
allowHalfOpen: true,
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false
|
||||||
};
|
};
|
||||||
@ -167,24 +179,26 @@ test(function serverResponseTimeoutWithPipeline(cb) {
|
|||||||
c.write('GET /2 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');
|
c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n');
|
||||||
});
|
});
|
||||||
});
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
test(function idleTimeout(cb) {
|
test(function idleTimeout(cb) {
|
||||||
const server = https.createServer(serverOptions,
|
const server = https.createServer(
|
||||||
|
serverOptions,
|
||||||
common.mustCall(function(req, res) {
|
common.mustCall(function(req, res) {
|
||||||
req.on('timeout', common.mustNotCall());
|
req.on('timeout', common.mustNotCall());
|
||||||
res.on('timeout', common.mustNotCall());
|
res.on('timeout', common.mustNotCall());
|
||||||
res.end();
|
res.end();
|
||||||
}));
|
}));
|
||||||
server.setTimeout(50, common.mustCall(function(socket) {
|
const s = server.setTimeout(50, common.mustCall(function(socket) {
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
server.close();
|
server.close();
|
||||||
cb();
|
cb();
|
||||||
}));
|
}));
|
||||||
server.listen(0, function() {
|
assert.ok(s instanceof https.Server);
|
||||||
|
server.listen(common.mustCall(function() {
|
||||||
const options = {
|
const options = {
|
||||||
port: this.address().port,
|
port: server.address().port,
|
||||||
allowHalfOpen: true,
|
allowHalfOpen: true,
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false
|
||||||
};
|
};
|
||||||
@ -192,5 +206,5 @@ test(function idleTimeout(cb) {
|
|||||||
this.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
|
this.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
|
||||||
// Keep-Alive
|
// Keep-Alive
|
||||||
});
|
});
|
||||||
});
|
}));
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user