From d8ba2c0de4681fd22967a9d6d5981f3abe0658a8 Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Sun, 10 Jan 2016 00:48:49 +0100 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/4602 Reviewed-By: Brian White Reviewed-By: James M Snell --- test/parallel/test-http-upgrade-client.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-http-upgrade-client.js b/test/parallel/test-http-upgrade-client.js index dc4dd47cf202c5..a45c06b44e04f0 100644 --- a/test/parallel/test-http-upgrade-client.js +++ b/test/parallel/test-http-upgrade-client.js @@ -40,9 +40,14 @@ srv.listen(common.PORT, '127.0.0.1', function() { } }); req.on('upgrade', function(res, socket, upgradeHead) { - // XXX: This test isn't fantastic, as it assumes that the entire response - // from the server will arrive in a single data callback - assert.equal(upgradeHead, 'nurtzo'); + var recvData = upgradeHead; + socket.on('data', function(d) { + recvData += d; + }); + + socket.on('close', common.mustCall(function() { + assert.equal(recvData, 'nurtzo'); + })); console.log(res.headers); var expectedHeaders = {'hello': 'world',