Browse Source

test: fix http-writable-true-after-close flakyness

Ref: https://github.com/nodejs/node/pull/15404
Fixes: https://github.com/nodejs/node/issues/15505
PR-URL: https://github.com/nodejs/node/pull/15520
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
canary-base
Matteo Collina 7 years ago
parent
commit
1fe9b535a7
  1. 29
      test/parallel/test-http-writable-true-after-close.js

29
test/parallel/test-http-writable-true-after-close.js

@ -7,29 +7,36 @@ const { get, createServer } = require('http');
// res.writable should not be set to false after it has finished sending // res.writable should not be set to false after it has finished sending
// Ref: https://github.com/nodejs/node/issues/15029 // Ref: https://github.com/nodejs/node/issues/15029
let internal;
let external; let external;
// Http server
const internal = createServer((req, res) => {
res.writeHead(200);
setImmediate(common.mustCall(() => {
external.abort();
res.end('Hello World\n');
}));
}).listen(0);
// Proxy server // Proxy server
const server = createServer(common.mustCall((req, res) => { const server = createServer(common.mustCall((req, res) => {
get(`http://127.0.0.1:${internal.address().port}`, common.mustCall((inner) => { get(`http://127.0.0.1:${internal.address().port}`, common.mustCall((inner) => {
res.on('close', common.mustCall(() => { const listener = common.mustCall(() => {
assert.strictEqual(res.writable, true); assert.strictEqual(res.writable, true);
})); });
// on CentOS 5, 'finish' is emitted
res.on('finish', listener);
// everywhere else, 'close' is emitted
res.on('close', listener);
inner.pipe(res); inner.pipe(res);
})); }));
})).listen(0, () => { })).listen(0, () => {
// Http server
internal = createServer((req, res) => {
res.writeHead(200);
setImmediate(common.mustCall(() => {
external.abort();
res.end('Hello World\n');
}));
}).listen(0, () => {
external = get(`http://127.0.0.1:${server.address().port}`); external = get(`http://127.0.0.1:${server.address().port}`);
external.on('error', common.mustCall((err) => { external.on('error', common.mustCall((err) => {
server.close(); server.close();
internal.close(); internal.close();
})); }));
}); });
});

Loading…
Cancel
Save