Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed ports.free() bug when passed just a number, role wasn't getting…

… unallocated
  • Loading branch information...
commit 36f7b0498f66d57842de6a2c05dcf59267306e16 1 parent 80fa7e7
@mbrevoort authored
Showing with 41 additions and 1 deletion.
  1. +3 −1 index.js
  2. +38 −0 test/free_port.js
View
4 index.js
@@ -302,7 +302,9 @@ exports.createServer = function (opts) {
Object.keys(roles).forEach(function (role) {
var rs = roles[role];
roles[role] = rs.filter(function (r) {
- var x = r.port === port && r.host === host && r._id === id;
+ // if no id passed into free, don't consider it
+ var idCondition = (!id || r._id === id);
+ var x = r.port === port && r.host === host && idCondition;
if (x) {
var ix = allocated.indexOf(r);
if (ix >= 0) allocated.splice(ix, 1);
View
38 test/free_port.js
@@ -0,0 +1,38 @@
+var test = require('tap').test;
+var seaport = require('../');
+
+// same exact test as free.js but passing ports.free a number parameter
+test('free', function (t) {
+ t.plan(6);
+ var port = Math.floor(Math.random() * 5e4 + 1e4);
+ var server = seaport.createServer();
+ server.listen(port);
+
+ var ports = seaport.connect('localhost', port);
+ var gotPort, gotRec;
+ server.on('free', function (rec) {
+ t.same(rec, gotRec);
+ t.same(server.allocated[gotRec.host], []);
+ ports.close();
+ });
+
+ ports.allocate('http', function (p) {
+ t.ok(p >= 10000 && p < 65536);
+ gotPort = p;
+
+ process.nextTick(function () {
+ ports.query('http', function (ps) {
+ t.equal(ps.length, 1);
+ t.equal(ps[0].host, '127.0.0.1');
+ t.equal(ps[0].port, gotPort);
+
+ gotRec = ps[0];
+ ports.free(ps[0].port);
+ });
+ });
+ });
+
+ t.on('end', function () {
+ server.close();
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.