Permalink
Browse files

failing test when subscription is delayed

  • Loading branch information...
1 parent 3226531 commit 0e5e0c64c2c7a8bb1054c058b54c31f8c182fd91 @substack committed May 16, 2012
Showing with 44 additions and 0 deletions.
  1. +44 −0 test/resubscribe.js
View
44 test/resubscribe.js
@@ -42,3 +42,47 @@ test('resubscribe if connection dies', function(t) {
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);
+
+ t.on('end', function() {
+ server.close();
+ client.close();
+ t.ok(true, 'closed server');
+ });
+});

0 comments on commit 0e5e0c6

Please sign in to comment.