Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

passing resub delay tests

  • Loading branch information...
commit c0729395761e151db74e7ce2f52fd5422f3dc4dc 1 parent 0e5e0c6
@substack authored
Showing with 54 additions and 53 deletions.
  1. +4 −3 index.js
  2. +5 −50 test/resubscribe.js
  3. +45 −0 test/resubscribe_delay.js
View
7 index.js
@@ -48,9 +48,10 @@ exports.connect = function () {
})
;
- self.subscribe = function(eventName, cb) {
- up.on('up', function () {
- up.remote.subscribe(eventName, cb);
+ self.subscribe = function (eventName, cb) {
+ if (up.remote) up.remote.subscribe(eventName, cb);
+ up.on('up', function (remote) {
+ remote.subscribe(eventName, cb);
});
};
View
55 test/resubscribe.js
@@ -2,11 +2,10 @@ var seaport = require('../');
var test = require('tap').test;
test('resubscribe if connection dies', function(t) {
- var serverPort = Math.floor(Math.random() * 5e4 + 1e4),
- server = seaport.createServer(),
- client = seaport.connect('localhost:' + serverPort, {reconnect: 10}),
- allocatedPort = 1234;
-
+ var serverPort = Math.floor(Math.random() * 5e4 + 1e4);
+ var server = seaport.createServer();
+ var client = seaport.connect('localhost:' + serverPort, {reconnect: 10});
+
t.plan(6);
var eventNames = ['allocate', 'assume', 'free'];
@@ -32,51 +31,7 @@ test('resubscribe if connection dies', function(t) {
setTimeout(function() {
client.up.conn.stream.end();
}, 400);
-
- // Run second test
- setTimeout(emit, 1600);
-
- t.on('end', function() {
- server.close();
- client.close();
- t.ok(true, 'closed server');
- });
-});
-
-test('resubscribe with delayed subscription', function(t) {
- var serverPort = Math.floor(Math.random() * 5e4 + 1e4),
- server = seaport.createServer(),
- client = seaport.connect('localhost:' + serverPort, {reconnect: 10}),
- allocatedPort = 1234;
-
- t.plan(6);
-
- var eventNames = ['allocate', 'assume', 'free'];
-
- setTimeout(function () {
- eventNames.forEach(function(eventName) {
- client.subscribe(eventName, function() {
- t.ok(true, eventName + ' emitted');
- });
- });
- }, 100);
-
- function emit() {
- eventNames.forEach(function(eventName) {
- server.emit(eventName, {});
- });
- }
-
- server.listen(serverPort);
-
- // Wait for client to connect
- setTimeout(emit, 200)
-
- // Wait for first tests to finish
- setTimeout(function() {
- client.up.conn.stream.end();
- }, 400);
-
+
// Run second test
setTimeout(emit, 1600);
View
45 test/resubscribe_delay.js
@@ -0,0 +1,45 @@
+var seaport = require('../');
+var test = require('tap').test;
+
+test('resubscribe with delayed subscription', function(t) {
+ var serverPort = Math.floor(Math.random() * 5e4 + 1e4);
+ var server = seaport.createServer();
+ var client = seaport.connect('localhost:' + serverPort, {reconnect: 10});
+
+ t.plan(6);
+
+ var eventNames = ['allocate', 'assume', 'free'];
+
+ setTimeout(function () {
+ eventNames.forEach(function(eventName) {
+ client.subscribe(eventName, function() {
+ t.ok(true, eventName + ' emitted');
+ });
+ });
+ }, 100);
+
+ function emit() {
+ eventNames.forEach(function(eventName) {
+ server.emit(eventName, {});
+ });
+ }
+
+ server.listen(serverPort);
+
+ // Wait for client to connect
+ setTimeout(emit, 200)
+
+ // Wait for first tests to finish
+ setTimeout(function() {
+ client.up.conn.stream.end();
+ }, 400);
+
+ // Run second test
+ setTimeout(emit, 1600);
+
+ t.on('end', function() {
+ server.close();
+ client.close();
+ t.ok(true, 'closed server');
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.