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.
pull/24503/head
Ben Noordhuis 2012-04-16 17:57:41 +02:00
parent 48d52d85c3
commit 21d2683976
1 changed files with 27 additions and 29 deletions

View File

@ -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,20 +38,21 @@ 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({
}).listen(common.PORT, function() {
var req = https.request({
host: 'localhost',
port: common.PORT,
path: '/',
method: 'GET'
});
req.end();
req.on('response', function(res) {
console.log('got response');
});
});
req.setTimeout(10);
req.end();
req.on('socket', function() {
req.on('response', function(res) {
console.log('got response');
});
req.on('socket', function() {
console.log('got a socket');
req.socket.on('connect', function() {
@ -63,13 +62,12 @@ req.on('socket', function() {
setTimeout(function() {
throw new Error('Did not get timeout event');
}, 200);
});
});
req.setTimeout(10);
req.on('timeout', function() {
req.on('timeout', function() {
console.log('timeout occurred outside');
req.destroy();
server.close();
process.exit(0);
});
});