Browse Source

Fix race conditions in test-http-upgrade-client2

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
40f675b64b
  1. 68
      test/simple/test-http-upgrade-client2.js

68
test/simple/test-http-upgrade-client2.js

@ -12,51 +12,55 @@ server.on('upgrade', function(req, socket, head) {
socket.end();
});
});
server.listen(8000);
var client = http.createClient(8000);
function upgradeRequest(fn) {
var request = client.request('GET', '/', {
'Connection': 'Upgrade',
'Upgrade': 'Test'
});
server.listen(common.PORT, function () {
var wasUpgrade = false;
var client = http.createClient(common.PORT);
function onUpgrade(res, socket, head) {
wasUpgrade = true;
function upgradeRequest(fn) {
var request = client.request('GET', '/', {
'Connection': 'Upgrade',
'Upgrade': 'Test'
});
client.removeListener('upgrade', onUpgrade);
socket.end();
}
client.on('upgrade', onUpgrade);
var wasUpgrade = false;
function onEnd() {
client.removeListener('end', onEnd);
if (!wasUpgrade) {
throw new Error('hasn\'t received upgrade event');
} else {
fn && process.nextTick(fn);
function onUpgrade(res, socket, head) {
wasUpgrade = true;
client.removeListener('upgrade', onUpgrade);
socket.end();
}
}
client.on('end', onEnd);
client.on('upgrade', onUpgrade);
request.write('head');
function onEnd() {
client.removeListener('end', onEnd);
if (!wasUpgrade) {
throw new Error('hasn\'t received upgrade event');
} else {
fn && process.nextTick(fn);
}
}
client.on('end', onEnd);
request.write('head');
}
}
successCount = 0;
upgradeRequest(function() {
successCount++;
successCount = 0;
upgradeRequest(function() {
successCount++;
// Test pass
console.log('Pass!');
client.end();
client.destroy();
server.close();
upgradeRequest(function() {
successCount++;
// Test pass
console.log('Pass!');
client.end();
client.destroy();
server.close();
});
});
});
process.on('exit', function () {

Loading…
Cancel
Save