Permalink
Browse files

Tweaked free to ignore the id for port only checks

  • Loading branch information...
1 parent 68ad151 commit ef83c0b4956a03df74f01e6bfc4c6514327eae76 @DamonOehlman DamonOehlman committed Sep 21, 2012
Showing with 38 additions and 1 deletion.
  1. +1 −1 index.js
  2. +37 −0 test/free-portonly.js
View
2 index.js
@@ -302,7 +302,7 @@ 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;
+ var x = r.port === port && r.host === host && (!id || r._id === id);
if (x) {
var ix = allocated.indexOf(r);
if (ix >= 0) allocated.splice(ix, 1);
View
37 test/free-portonly.js
@@ -0,0 +1,37 @@
+var test = require('tap').test;
+var seaport = require('../');
+
+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();
+ });
+});

0 comments on commit ef83c0b

Please sign in to comment.