Permalink
Browse files

failing test for meta params

  • Loading branch information...
1 parent 6e8a97e commit 6672b8733383c20a372adf553450adec51f22947 @substack committed Mar 6, 2012
Showing with 52 additions and 0 deletions.
  1. +52 −0 test/meta.js
View
@@ -0,0 +1,52 @@
+var test = require('tap').test;
+var seaport = require('../');
+
+test('allocate with metadata', function (t) {
+ t.plan(8);
+ var port = Math.floor(Math.random() * 5e5 + 1e5);
+ var server = seaport.createServer();
+
+ var gotPort;
+ server.on('allocate', function (alloc) {
+ t.equal(gotPort, alloc.port);
+ t.equal(alloc.beep, 'boop');
+ t.equal(alloc.host, '127.1.2.3');
+
+ ports.query('http', function (ps) {
+ t.equal(ps.length, 1);
+ t.equal(ps[0].host, '127.1.2.3');
+ t.equal(ps[0].port, gotPort);
+ t.equal(ps[0].beep, 'boop');
+ ports.close();
+ });
+ });
+
+ server.on('free', function () {
+ ports = seaport.connect('localhost', port);
+ ports.assume('http', gotPort);
+ });
+
+ server.on('assume', function (alloc) {
+ t.equal(alloc.port, gotPort);
+ t.equal(alloc.beep, 'boop');
+ t.equal(alloc.host, '127.1.2.3');
+
+ ports.close();
+ server.close();
+ t.end();
+ setTimeout(function () {
+ process.exit(); // whatever
+ }, 100);
+ });
+
+ server.listen(port);
+
+ var ports = seaport.connect('localhost', port);
+ ports.allocate(
+ { role : 'http', beep : 'boop', host : '127.1.2.3' },
+ function (p) {
+ t.ok(p >= 10000 && p < 65536);
+ gotPort = p;
+ }
+ );
+});

0 comments on commit 6672b87

Please sign in to comment.