test: fix `http-upgrade-client` flakiness
authorSantiago Gimeno <santiago.gimeno@gmail.com>
Sat, 9 Jan 2016 23:48:49 +0000 (00:48 +0100)
committerMyles Borins <mborins@us.ibm.com>
Mon, 15 Feb 2016 19:30:23 +0000 (11:30 -0800)
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 <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
test/parallel/test-http-upgrade-client.js

index b8ba033..a86b0e3 100644 (file)
@@ -34,9 +34,14 @@ srv.listen(common.PORT, '127.0.0.1', function() {
 
   var req = http.get({ port: common.PORT });
   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',