Skip to content

Commit

Permalink
test: fix http-writable-true-after-close flakyness
Browse files Browse the repository at this point in the history
Ref: #15404
Fixes: #15505
PR-URL: #15520
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
mcollina authored and MylesBorins committed Oct 3, 2017
1 parent 69f8738 commit 0aea258
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions test/parallel/test-http-writable-true-after-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,36 @@ const { get, createServer } = require('http');
// res.writable should not be set to false after it has finished sending
// Ref: https://github.com/nodejs/node/issues/15029

let internal;
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
const server = createServer(common.mustCall((req, res) => {
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);
}));
});

// on CentOS 5, 'finish' is emitted
res.on('finish', listener);
// everywhere else, 'close' is emitted
res.on('close', listener);

inner.pipe(res);
}));
})).listen(0, () => {
external = get(`http://127.0.0.1:${server.address().port}`);
external.on('error', common.mustCall((err) => {
server.close();
internal.close();
}));
// 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.on('error', common.mustCall((err) => {
server.close();
internal.close();
}));
});
});

0 comments on commit 0aea258

Please sign in to comment.