From 38f117cb6df78fc9ec718da9dae8918f80b08ffc Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sat, 23 Oct 2010 14:26:31 -0700 Subject: [PATCH] one more 'listening' race condition --- test/simple/test-http-upgrade-client.js | 41 +++++++++++++------------ 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/test/simple/test-http-upgrade-client.js b/test/simple/test-http-upgrade-client.js index b09cc58a27..be6c386ef2 100644 --- a/test/simple/test-http-upgrade-client.js +++ b/test/simple/test-http-upgrade-client.js @@ -26,28 +26,31 @@ var srv = net.createServer(function(c) { c.end(); }); }); -srv.listen(common.PORT, '127.0.0.1'); var gotUpgrade = false; -var hc = http.createClient(common.PORT, '127.0.0.1'); -hc.addListener('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'); - - console.log(res.headers); - var expectedHeaders = { "hello": "world" - , "connection": "upgrade" - , "upgrade": "websocket" - }; - assert.deepEqual(expectedHeaders, res.headers); - - socket.end(); - srv.close(); - - gotUpgrade = true; + +srv.listen(common.PORT, '127.0.0.1', function () { + + var hc = http.createClient(common.PORT, '127.0.0.1'); + hc.addListener('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'); + + console.log(res.headers); + var expectedHeaders = { "hello": "world" + , "connection": "upgrade" + , "upgrade": "websocket" + }; + assert.deepEqual(expectedHeaders, res.headers); + + socket.end(); + srv.close(); + + gotUpgrade = true; + }); + hc.request('GET', '/').end(); }); -hc.request('GET', '/').end(); process.addListener('exit', function() { assert.ok(gotUpgrade);