Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

test: don't make request until server is listening

Preemptively fixes simple/test-https-timeout on platforms where binding to an
interface is not an instantaneous action.
  • Loading branch information...
bnoordhuis committed Apr 16, 2012
1 parent 48d52d8 commit 21d26839762c52f20edcfcc245a0cfe1acb21196
Showing with 27 additions and 29 deletions.
  1. +27 −29 test/simple/test-https-timeout.js
@@ -26,10 +26,8 @@ if (!process.versions.openssl) {

var common = require('../common');
var assert = require('assert');

var fs = require('fs');
var exec = require('child_process').exec;

var https = require('https');

var options = {
@@ -40,36 +38,36 @@ var options = {
// a server that never replies
var server = https.createServer(options, function() {
console.log('Got request. Doing nothing.');
}).listen(common.PORT);

var req = https.request({
host: 'localhost',
port: common.PORT,
path: '/',
method: 'GET'
});
req.end();
req.on('response', function(res) {
console.log('got response');
});

req.on('socket', function() {
console.log('got a socket');
}).listen(common.PORT, function() {
var req = https.request({
host: 'localhost',
port: common.PORT,
path: '/',
method: 'GET'
});
req.setTimeout(10);
req.end();

req.socket.on('connect', function() {
console.log('socket connected');
req.on('response', function(res) {
console.log('got response');
});

setTimeout(function() {
throw new Error('Did not get timeout event');
}, 200);
});
req.on('socket', function() {
console.log('got a socket');

req.setTimeout(10);
req.socket.on('connect', function() {
console.log('socket connected');
});

req.on('timeout', function() {
console.log('timeout occurred outside');
req.destroy();
server.close();
process.exit(0);
setTimeout(function() {
throw new Error('Did not get timeout event');
}, 200);
});

req.on('timeout', function() {
console.log('timeout occurred outside');
req.destroy();
server.close();
process.exit(0);
});
});

0 comments on commit 21d2683

Please sign in to comment.
You can’t perform that action at this time.