Browse Source

one more 'listening' race condition

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
38f117cb6d
  1. 41
      test/simple/test-http-upgrade-client.js

41
test/simple/test-http-upgrade-client.js

@ -26,28 +26,31 @@ var srv = net.createServer(function(c) {
c.end(); c.end();
}); });
}); });
srv.listen(common.PORT, '127.0.0.1');
var gotUpgrade = false; var gotUpgrade = false;
var hc = http.createClient(common.PORT, '127.0.0.1');
hc.addListener('upgrade', function(res, socket, upgradeHead) { srv.listen(common.PORT, '127.0.0.1', function () {
// XXX: This test isn't fantastic, as it assumes that the entire response
// from the server will arrive in a single data callback var hc = http.createClient(common.PORT, '127.0.0.1');
assert.equal(upgradeHead, 'nurtzo'); hc.addListener('upgrade', function(res, socket, upgradeHead) {
// XXX: This test isn't fantastic, as it assumes that the entire response
console.log(res.headers); // from the server will arrive in a single data callback
var expectedHeaders = { "hello": "world" assert.equal(upgradeHead, 'nurtzo');
, "connection": "upgrade"
, "upgrade": "websocket" console.log(res.headers);
}; var expectedHeaders = { "hello": "world"
assert.deepEqual(expectedHeaders, res.headers); , "connection": "upgrade"
, "upgrade": "websocket"
socket.end(); };
srv.close(); assert.deepEqual(expectedHeaders, res.headers);
gotUpgrade = true; socket.end();
srv.close();
gotUpgrade = true;
});
hc.request('GET', '/').end();
}); });
hc.request('GET', '/').end();
process.addListener('exit', function() { process.addListener('exit', function() {
assert.ok(gotUpgrade); assert.ok(gotUpgrade);

Loading…
Cancel
Save