From 21d26839762c52f20edcfcc245a0cfe1acb21196 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 16 Apr 2012 17:57:41 +0200 Subject: [PATCH] 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. --- test/simple/test-https-timeout.js | 56 +++++++++++++++---------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/test/simple/test-https-timeout.js b/test/simple/test-https-timeout.js index 6bc0ec5291..8a8ae00c3c 100644 --- a/test/simple/test-https-timeout.js +++ b/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); + }); });