Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

passing custom query test with multiple records

  • Loading branch information...
commit b6ec547857a492c53693e0ba7c8927bba712c624 1 parent 1b73d5e
James Halliday authored

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

  1. +56 0 test/sub.js
56 test/sub.js
... ... @@ -0,0 +1,56 @@
  1 +var test = require('tap').test;
  2 +var seaport = require('seaport');
  3 +var pier = require('../');
  4 +
  5 +test('up and down', function (t) {
  6 + t.plan(16);
  7 + var port = Math.floor(1e4 + 5e4 * Math.random());
  8 +
  9 + var server = seaport.createServer().listen(port);
  10 + var cache = pier('beep').tie(port);
  11 + var ports = seaport.connect(port);
  12 +
  13 + t.on('end', function () {
  14 + console.log('end');
  15 + ports.close();
  16 + server.close();
  17 + cache.close();
  18 + });
  19 +
  20 + setTimeout(function () {
  21 + t.same([], cache.query());
  22 + ports.assume('robots', 9996);
  23 + ports.assume('boop', 9997);
  24 + ports.assume('beep', 9998);
  25 + ports.assume('beep', 9999);
  26 +
  27 + function cmp (records) {
  28 + t.equal(records.length, 2);
  29 +
  30 + t.equal(records[0].host, '127.0.0.1');
  31 + t.equal(records[0].port, 9998);
  32 + t.equal(records[0].role, 'beep');
  33 +
  34 + t.equal(records[1].host, '127.0.0.1');
  35 + t.equal(records[1].port, 9999);
  36 + t.equal(records[1].role, 'beep');
  37 + }
  38 + var pending0 = 2;
  39 + cache.on('update', function fn (records) {
  40 + if (--pending0 !== 0) return;
  41 + cache.removeListener('update', fn);
  42 +
  43 + cmp(records);
  44 + cmp(cache.query('beep'));
  45 +
  46 + var pending1 = 2;
  47 + cache.on('update', function fn (records) {
  48 + if (--pending1 !== 0) return;
  49 + cache.removeListener('update', fn);
  50 + t.same(records, []);
  51 + });
  52 + ports.free({ role : 'beep', port : 9998 });
  53 + ports.free({ role : 'beep', port : 9999 });
  54 + });
  55 + }, 100);
  56 +});

0 comments on commit b6ec547

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