Skip to content
This repository
Browse code

failing test when subscription is delayed

  • Loading branch information...
commit 0e5e0c64c2c7a8bb1054c058b54c31f8c182fd91 1 parent 3226531
James Halliday authored

Showing 1 changed file with 44 additions and 0 deletions. Show diff stats Hide diff stats

  1. +44 0 test/resubscribe.js
44 test/resubscribe.js
@@ -42,3 +42,47 @@ test('resubscribe if connection dies', function(t) {
42 42 t.ok(true, 'closed server');
43 43 });
44 44 });
  45 +
  46 +test('resubscribe with delayed subscription', function(t) {
  47 + var serverPort = Math.floor(Math.random() * 5e4 + 1e4),
  48 + server = seaport.createServer(),
  49 + client = seaport.connect('localhost:' + serverPort, {reconnect: 10}),
  50 + allocatedPort = 1234;
  51 +
  52 + t.plan(6);
  53 +
  54 + var eventNames = ['allocate', 'assume', 'free'];
  55 +
  56 + setTimeout(function () {
  57 + eventNames.forEach(function(eventName) {
  58 + client.subscribe(eventName, function() {
  59 + t.ok(true, eventName + ' emitted');
  60 + });
  61 + });
  62 + }, 100);
  63 +
  64 + function emit() {
  65 + eventNames.forEach(function(eventName) {
  66 + server.emit(eventName, {});
  67 + });
  68 + }
  69 +
  70 + server.listen(serverPort);
  71 +
  72 + // Wait for client to connect
  73 + setTimeout(emit, 200)
  74 +
  75 + // Wait for first tests to finish
  76 + setTimeout(function() {
  77 + client.up.conn.stream.end();
  78 + }, 400);
  79 +
  80 + // Run second test
  81 + setTimeout(emit, 1600);
  82 +
  83 + t.on('end', function() {
  84 + server.close();
  85 + client.close();
  86 + t.ok(true, 'closed server');
  87 + });
  88 +});

0 comments on commit 0e5e0c6

Please sign in to comment.
Something went wrong with that request. Please try again.