mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 21:58:48 +02:00
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
2 changed files with 111 additions and 85 deletions
|
@ -42,22 +42,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();
|
||||
}));
|
||||
assert.ok(s instanceof http.Server);
|
||||
http.get({
|
||||
port: server.address().port
|
||||
}).on('error', common.mustCall());
|
||||
}));
|
||||
const s = server.setTimeout(50, common.mustCall(function(socket) {
|
||||
socket.destroy();
|
||||
server.close();
|
||||
cb();
|
||||
}));
|
||||
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();
|
||||
|
@ -65,10 +67,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
|
||||
|
@ -76,7 +80,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();
|
||||
|
@ -84,28 +88,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());
|
||||
}));
|
||||
});
|
||||
|
||||
|
@ -124,16 +130,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');
|
||||
|
@ -142,11 +151,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();
|
||||
|
@ -154,8 +163,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
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue