Skip to content

Commit 6018fa1

Browse files
santigimenojasnell
authored andcommitted
test: fix http-upgrade-agent flakiness
It's not guaranteed that the socket data is received in the same chunk as the upgrade response. Listen for the `data` event to make sure all the data is received. PR-URL: #4520 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 3a7f106 commit 6018fa1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

test/parallel/test-http-upgrade-agent.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,14 @@ srv.listen(common.PORT, '127.0.0.1', function() {
4646
req.end();
4747

4848
req.on('upgrade', function(res, socket, upgradeHead) {
49-
// XXX: This test isn't fantastic, as it assumes that the entire response
50-
// from the server will arrive in a single data callback
51-
assert.equal(upgradeHead, 'nurtzo');
49+
var recvData = upgradeHead;
50+
socket.on('data', function(d) {
51+
recvData += d;
52+
});
53+
54+
socket.on('close', common.mustCall(function() {
55+
assert.equal(recvData, 'nurtzo');
56+
}));
5257

5358
console.log(res.headers);
5459
var expectedHeaders = { 'hello': 'world',

0 commit comments

Comments
 (0)