Skip to content

Commit

Permalink
test: fixed flaky test-http-readable-data-event
Browse files Browse the repository at this point in the history
Fixes: #19905
  • Loading branch information
mcollina committed Apr 11, 2018
1 parent 8170f4f commit 4865576
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions test/parallel/test-http-readable-data-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ const http = require('http');
const helloWorld = 'Hello World!';
const helloAgainLater = 'Hello again later!';

let next = null;

const server = http.createServer((req, res) => {
res.writeHead(200, {
'Content-Length': '' + (helloWorld.length + helloAgainLater.length)
});
res.write(helloWorld);

// we need to make sure the data is flushed
setTimeout(() => {
// before writing again
next = () => {
res.end(helloAgainLater);
}, common.platformTimeout(10));
next = () => {};
};

res.write(helloWorld);
}).listen(0, function() {
const opts = {
hostname: 'localhost',
Expand All @@ -27,14 +32,15 @@ const server = http.createServer((req, res) => {
const expectedRead = [helloWorld, null, helloAgainLater, null];

const req = http.request(opts, (res) => {
res.on('error', common.mustNotCall);
res.on('error', common.mustNotCall());

res.on('readable', common.mustCall(() => {
let data;

do {
data = res.read();
assert.strictEqual(data, expectedRead.shift());
next();
} while (data !== null);
}, 2));

Expand Down

0 comments on commit 4865576

Please sign in to comment.