Skip to content

Commit

Permalink
Merge pull request #2205 from simov/fix-test-timeout
Browse files Browse the repository at this point in the history
Use server-destory to close hanging sockets in tests
  • Loading branch information
simov committed May 7, 2016
2 parents 4482576 + 926ebd8 commit 1cd1747
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
8 changes: 6 additions & 2 deletions tests/test-httpModule.js
Expand Up @@ -2,6 +2,7 @@

var http = require('http')
, https = require('https')
, destroyable = require('server-destroy')
, server = require('./server')
, request = require('../index')
, tape = require('tape')
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
})
})
Expand Down
8 changes: 6 additions & 2 deletions tests/test-redirect-auth.js
Expand Up @@ -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 : {
Expand Down Expand Up @@ -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()
})
})
Expand Down
8 changes: 6 additions & 2 deletions tests/test-redirect-complex.js
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
})
})
Expand Down
8 changes: 6 additions & 2 deletions tests/test-redirect.js
Expand Up @@ -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 + '/'
Expand Down Expand Up @@ -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()
})
})
Expand Down

0 comments on commit 1cd1747

Please sign in to comment.