Permalink
Browse files

ignore supplied host params and everything is fine

  • Loading branch information...
1 parent 82cba1a commit fd612e2f620a206b5b349c233d2f9c8549a7e08e @substack committed Mar 6, 2012
Showing with 9 additions and 8 deletions.
  1. +6 −6 index.js
  2. +3 −2 test/meta.js
View
@@ -138,7 +138,7 @@ exports.createServer = function (opts) {
function ready () {
ports[addr].push(port);
- if (params.host === undefined) params.host = addr;
+ params.host = addr;
params.port = port;
params.version = version;
params.role = role;
@@ -169,7 +169,7 @@ exports.createServer = function (opts) {
}
var role = roleVer.split('@')[0];
- var version = params.version || roleVer.split('@')[1];
+ var version = params.version || roleVer.split('@')[1] || '0.0.0';
var ix = ports[addr].indexOf(port);
if (ix >= 0) ports[addr].splice(ix, 1);
@@ -180,7 +180,7 @@ exports.createServer = function (opts) {
return r.port !== port;
});
- params.host = params.host || addr;
+ params.host = addr;
params.port = port;
params.role = role;
params.version = version;
@@ -201,8 +201,8 @@ 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 === addr);
- if (!x) {
+ var x = r.port === port && r.host === addr;
+ if (x) {
found = {};
Object.keys(r).forEach(function (key) {
found[key] = r[key];
@@ -211,7 +211,7 @@ exports.createServer = function (opts) {
if (!found.port) found.port = port;
found.role = role;
}
- return x;
+ return !x;
});
});
View
@@ -10,18 +10,19 @@ test('allocate with metadata', function (t) {
server.on('allocate', function (alloc) {
t.equal(gotPort, alloc.port);
t.equal(alloc.beep, 'boop');
- t.equal(alloc.host, '127.1.2.3');
+ t.equal(alloc.host, '127.0.0.1', 'ignore the supplied host');
ports.query('http', function (ps) {
t.equal(ps.length, 1);
- t.equal(ps[0].host, '127.1.2.3');
+ t.equal(ps[0].host, '127.0.0.1', 'ignore the supplied host');
t.equal(ps[0].port, gotPort);
t.equal(ps[0].beep, 'boop');
ports.close();
});
});
server.on('free', function (alloc) {
+//console.error(alloc);
t.equal(alloc.beep, 'boop');
ports = seaport.connect('localhost', port);
ports.assume('http', { port : gotPort, foo : 'bar' });

0 comments on commit fd612e2

Please sign in to comment.