Skip to content

Commit 3d5bc69

Browse files
santigimenoMyles Borins
authored and
Myles Borins
committed
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 <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent ec24d37 commit 3d5bc69

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ srv.listen(common.PORT, '127.0.0.1', function() {
4545
req.end();
4646

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

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

0 commit comments

Comments
 (0)