Skip to content

Commit d8ba2c0

Browse files
santigimenojasnell
authored andcommitted
test: fix http-upgrade-client 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: #4602 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 6018fa1 commit d8ba2c0

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ srv.listen(common.PORT, '127.0.0.1', function() {
4040
}
4141
});
4242
req.on('upgrade', function(res, socket, upgradeHead) {
43-
// XXX: This test isn't fantastic, as it assumes that the entire response
44-
// from the server will arrive in a single data callback
45-
assert.equal(upgradeHead, 'nurtzo');
43+
var recvData = upgradeHead;
44+
socket.on('data', function(d) {
45+
recvData += d;
46+
});
47+
48+
socket.on('close', common.mustCall(function() {
49+
assert.equal(recvData, 'nurtzo');
50+
}));
4651

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

0 commit comments

Comments
 (0)