Skip to content

Commit 8f0cf38

Browse files
santigimenorvagg
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 afa4c1a commit 8f0cf38

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
@@ -34,9 +34,14 @@ srv.listen(common.PORT, '127.0.0.1', function() {
3434

3535
var req = http.get({ port: common.PORT });
3636
req.on('upgrade', function(res, socket, upgradeHead) {
37-
// XXX: This test isn't fantastic, as it assumes that the entire response
38-
// from the server will arrive in a single data callback
39-
assert.equal(upgradeHead, 'nurtzo');
37+
var recvData = upgradeHead;
38+
socket.on('data', function(d) {
39+
recvData += d;
40+
});
41+
42+
socket.on('close', common.mustCall(function() {
43+
assert.equal(recvData, 'nurtzo');
44+
}));
4045

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

0 commit comments

Comments
 (0)