-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: fixed flaky test-http-readable-data-event #19931
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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', | ||
|
@@ -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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
res.on('readable', common.mustCall(() => { | ||
let data; | ||
|
||
do { | ||
data = res.read(); | ||
assert.strictEqual(data, expectedRead.shift()); | ||
next(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to remove the // Here
if (!streamEnded) {
res.end(helloAgainLater);
streamEnded = true;
}
// At the top of the file
let streamEnded = false; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It’s not what the test is supposed to verify. The intent is that we need to wait for the first chunk to be received before sending the second. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
} while (data !== null); | ||
}, 2)); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bonus points for making an instance of
platformTimeout()
unnecessary.