Permalink
Browse files

passing port 0 test

  • Loading branch information...
1 parent c659b81 commit d8180b0778dd7a145b46f92b9a2d77db916debc5 @substack committed Nov 9, 2012
Showing with 39 additions and 1 deletion.
  1. +1 −1 index.js
  2. +38 −0 test/zero.js
View
@@ -108,7 +108,7 @@ dnode.prototype.listen = function () {
server.sessions = {};
- if(typeof params.port === 'number' && params.port >= 0) {
+ if (typeof params.port === 'number' && params.port >= 0) {
server.listen(params.port, params.host);
}
else if (params.path) {
View
@@ -0,0 +1,38 @@
+var dnode = require('../');
+var test = require('tap').test;
+
+test('listen on port 0', function (t) {
+ t.plan(7);
+
+ var server = dnode({
+ timesTen : function (n,reply) {
+ t.equal(n, 50);
+ reply(n * 10);
+ },
+ moo : function (reply) { reply(100) },
+ sTimesTen : function (n, cb) {
+ t.equal(n, 5);
+ cb(n * 10);
+ },
+ }).listen(0);
+
+ server.on('listening', function () {
+ dnode.connect(server.address().port, function (remote, conn) {
+ t.ok(conn.id);
+ t.equal(conn.stream.remoteAddress, '127.0.0.1');
+
+ remote.moo(function (x) {
+ t.equal(x, 100, 'remote moo == 100');
+ });
+ remote.sTimesTen(5, function (m) {
+ t.equal(m, 50, '5 * 10 == 50');
+ remote.timesTen(m, function (n) {
+ t.equal(n, 500, '50 * 10 == 500');
+ conn.end();
+ server.close();
+ t.end();
+ });
+ });
+ });
+ });
+});

0 comments on commit d8180b0

Please sign in to comment.