Skip to content

Commit 974d07d

Browse files
mcollinajasnell
authored andcommitted
test: fixed flaky test-http-readable-data-event
Fixes: #19905 PR-URL: #19931 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent 4766f51 commit 974d07d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

test/parallel/test-http-readable-data-event.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@ const http = require('http');
66
const helloWorld = 'Hello World!';
77
const helloAgainLater = 'Hello again later!';
88

9+
let next = null;
10+
911
const server = http.createServer((req, res) => {
1012
res.writeHead(200, {
1113
'Content-Length': '' + (helloWorld.length + helloAgainLater.length)
1214
});
13-
res.write(helloWorld);
1415

1516
// we need to make sure the data is flushed
16-
setTimeout(() => {
17+
// before writing again
18+
next = () => {
1719
res.end(helloAgainLater);
18-
}, common.platformTimeout(10));
20+
next = () => {};
21+
};
22+
23+
res.write(helloWorld);
1924
}).listen(0, function() {
2025
const opts = {
2126
hostname: 'localhost',
@@ -27,14 +32,15 @@ const server = http.createServer((req, res) => {
2732
const expectedRead = [helloWorld, null, helloAgainLater, null];
2833

2934
const req = http.request(opts, (res) => {
30-
res.on('error', common.mustNotCall);
35+
res.on('error', common.mustNotCall());
3136

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

3540
do {
3641
data = res.read();
3742
assert.strictEqual(data, expectedRead.shift());
43+
next();
3844
} while (data !== null);
3945
}, 2));
4046

0 commit comments

Comments
 (0)