0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-http-server-close-idle-wait-response.js
Paolo Insogna e119614a68 http: wait for pending responses in closeIdleConnections
PR-URL: https://github.com/nodejs/node/pull/43890
Fixes: https://github.com/nodejs/node/issues/43771
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2022-07-21 10:02:04 +02:00

27 lines
679 B
JavaScript

'use strict';
const common = require('../common');
const { createServer, get } = require('http');
const server = createServer(common.mustCall(function(req, res) {
req.resume();
setTimeout(common.mustCall(() => {
res.writeHead(204, { 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=1' });
res.end();
}), common.platformTimeout(1000));
}));
server.listen(0, function() {
const port = server.address().port;
get(`http://localhost:${port}`, common.mustCall((res) => {
server.close();
})).on('finish', common.mustCall(() => {
setTimeout(common.mustCall(() => {
server.closeIdleConnections();
}), common.platformTimeout(500));
}));
});