Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Use a random unused port. #64

Merged
merged 1 commit into from

2 participants

@calebcase

In situations where supertest is run multiple times in parallel on the
same host EADDRINUSE can result. This is due to the current method of
using port 3456 (+ offset). A more reliable method for obtaining a
random unused port is to specify port 0 and have the OS choose which
port to bind.

Fixes #62

@calebcase calebcase Use a random unused port.
In situations where supertest is run multiple times in parallel on the
same host EADDRINUSE can result. This is due to the current method of
using port 3456 (+ offset). A more reliable method for obtaining a
random unused port is to specify port 0 and have the OS choose which
port to bind.

Fixes #62
ebebf19
@tj
Owner
tj commented

weird, we should have used 0 all along, can't remember why that is not the case

@tj
Owner
tj commented

ah it snuck in with f481cfb

@tj tj merged commit 351b00b into visionmedia:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 20, 2013
  1. @calebcase

    Use a random unused port.

    calebcase authored
    In situations where supertest is run multiple times in parallel on the
    same host EADDRINUSE can result. This is due to the current method of
    using port 3456 (+ offset). A more reliable method for obtaining a
    random unused port is to specify port 0 and have the OS choose which
    port to bind.
    
    Fixes #62
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 4 deletions.
  1. +4 −4 lib/test.js
View
8 lib/test.js
@@ -14,7 +14,7 @@ var request = require('superagent')
* Starting port.
*/
-var port = 3456;
+var port = 0;
/**
* Expose `Test`.
@@ -61,10 +61,10 @@ Test.prototype.__proto__ = Request.prototype;
Test.prototype.serverAddress = function(app, path){
var addr = app.address();
- var portno = addr ? addr.port : port++;
- if (!addr) app.listen(portno);
+ if (!addr) app.listen(0);
+ port = app.address().port
var protocol = app instanceof https.Server ? 'https' : 'http';
- return protocol + '://127.0.0.1:' + portno + path;
+ return protocol + '://127.0.0.1:' + port + path;
};
/**
Something went wrong with that request. Please try again.