test: fix flaky test-http-set-timeout-server
It can happen that the connection and server is closed before the second reponse has been processed by server. In this case, the `res.setTimeout()` callback will never be called causing the test to fail. Fix this by only closing the connection and server when the 2nd has been received. PR-URL: https://github.com/nodejs/node/pull/11790 Fixes: https://github.com/nodejs/node/issues/11768 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
This commit is contained in:
parent
1d1dbcafa8
commit
3be1db8702
@ -138,10 +138,13 @@ test(function serverRequestNotTimeoutAfterEnd(cb) {
|
||||
|
||||
test(function serverResponseTimeoutWithPipeline(cb) {
|
||||
let caughtTimeout = '';
|
||||
let secReceived = false;
|
||||
process.on('exit', function() {
|
||||
assert.strictEqual(caughtTimeout, '/2');
|
||||
});
|
||||
const server = http.createServer(function(req, res) {
|
||||
if (req.url === '/2')
|
||||
secReceived = true;
|
||||
const s = res.setTimeout(50, function() {
|
||||
caughtTimeout += req.url;
|
||||
});
|
||||
@ -149,9 +152,11 @@ test(function serverResponseTimeoutWithPipeline(cb) {
|
||||
if (req.url === '/1') res.end();
|
||||
});
|
||||
server.on('timeout', function(socket) {
|
||||
socket.destroy();
|
||||
server.close();
|
||||
cb();
|
||||
if (secReceived) {
|
||||
socket.destroy();
|
||||
server.close();
|
||||
cb();
|
||||
}
|
||||
});
|
||||
server.listen(common.mustCall(function() {
|
||||
const port = server.address().port;
|
||||
|
Loading…
x
Reference in New Issue
Block a user