Permalink
Browse files

one more 'listening' race condition

  • Loading branch information...
1 parent 78afb12 commit a958ebfca0df499f9f83f8b464f48de74dd3f986 @ry ry committed Oct 23, 2010
Showing with 22 additions and 19 deletions.
  1. +22 −19 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);

0 comments on commit a958ebf

Please sign in to comment.