From 926ebd87f213e373a843681121d7013cbfdd9246 Mon Sep 17 00:00:00 2001 From: simov Date: Sat, 7 May 2016 20:12:21 +0300 Subject: [PATCH] Use server-destory to close hanging sockets when running the coverage report (in single process) --- tests/test-httpModule.js | 8 ++++++-- tests/test-redirect-auth.js | 8 ++++++-- tests/test-redirect-complex.js | 8 ++++++-- tests/test-redirect.js | 8 ++++++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/tests/test-httpModule.js b/tests/test-httpModule.js index dae4845a7..ee530e6f2 100644 --- a/tests/test-httpModule.js +++ b/tests/test-httpModule.js @@ -2,6 +2,7 @@ var http = require('http') , https = require('https') + , destroyable = require('server-destroy') , server = require('./server') , request = require('../index') , tape = require('tape') @@ -36,6 +37,9 @@ var faux_http = wrap_request('http', http) , plain_server = server.createServer() , https_server = server.createSSLServer() +destroyable(plain_server) +destroyable(https_server) + tape('setup', function(t) { plain_server.listen(plain_server.port, function() { plain_server.on('/plain', function (req, res) { @@ -100,8 +104,8 @@ run_tests('https only', { 'https:': faux_https }) run_tests('http and https', { 'http:': faux_http, 'https:': faux_https }) tape('cleanup', function(t) { - plain_server.close(function() { - https_server.close(function() { + plain_server.destroy(function() { + https_server.destroy(function() { t.end() }) }) diff --git a/tests/test-redirect-auth.js b/tests/test-redirect-auth.js index ecffdbd8b..95eaf04b6 100644 --- a/tests/test-redirect-auth.js +++ b/tests/test-redirect-auth.js @@ -4,10 +4,14 @@ var server = require('./server') , request = require('../index') , util = require('util') , tape = require('tape') + , destroyable = require('server-destroy') var s = server.createServer() , ss = server.createSSLServer() +destroyable(s) +destroyable(ss) + // always send basic auth and allow non-strict SSL request = request.defaults({ auth : { @@ -117,8 +121,8 @@ runTest('different host and protocol', false) tape('cleanup', function(t) { - s.close(function() { - ss.close(function() { + s.destroy(function() { + ss.destroy(function() { t.end() }) }) diff --git a/tests/test-redirect-complex.js b/tests/test-redirect-complex.js index c3ff7a031..b88ef178a 100644 --- a/tests/test-redirect-complex.js +++ b/tests/test-redirect-complex.js @@ -4,11 +4,15 @@ var server = require('./server') , request = require('../index') , events = require('events') , tape = require('tape') + , destroyable = require('server-destroy') var s = server.createServer() , ss = server.createSSLServer() , e = new events.EventEmitter() +destroyable(s) +destroyable(ss) + function bouncy(s, serverUrl) { var redirs = { a: 'b' , b: 'c' @@ -79,8 +83,8 @@ tape('lots of redirects', function(t) { }) tape('cleanup', function(t) { - s.close(function() { - ss.close(function() { + s.destroy(function() { + ss.destroy(function() { t.end() }) }) diff --git a/tests/test-redirect.js b/tests/test-redirect.js index 3c18f85b9..6b9e7ee33 100644 --- a/tests/test-redirect.js +++ b/tests/test-redirect.js @@ -5,12 +5,16 @@ var server = require('./server') , request = require('../index') , tape = require('tape') , http = require('http') + , destroyable = require('server-destroy') var s = server.createServer() , ss = server.createSSLServer() , hits = {} , jar = request.jar() +destroyable(s) +destroyable(ss) + s.on('/ssl', function(req, res) { res.writeHead(302, { location : ss.url + '/' @@ -419,8 +423,8 @@ tape('should use same agent class on redirect', function(t) { }) tape('cleanup', function(t) { - s.close(function() { - ss.close(function() { + s.destroy(function() { + ss.destroy(function() { t.end() }) })