Permalink
Browse files

failing round robin test

  • Loading branch information...
1 parent 8bae482 commit 0df63f837004249a19b6767452b5208defd1bc3d @substack committed Jan 17, 2012
Showing with 35 additions and 0 deletions.
  1. +35 −0 test/round.js
View
@@ -0,0 +1,35 @@
+var test = require('tap').test;
+var Waitlist = require('../');
+var EventEmitter = require('events').EventEmitter;
+
+test('round robins', function (t) {
+ var ws = new Waitlist;
+
+ ws.add(0, { id : 0 });
+ ws.add(1, { id : 1 });
+
+ var resources = [];
+ for (var i = 0; i < 10; i++) setTimeout(function () {
+ var e = new EventEmitter;
+ e.on('available', function (res, key, lease) {
+ resources.push(JSON.parse(JSON.stringify(res)));
+ });
+ ws.acquire(5, e.emit.bind(e));
+ }, 10 * i);
+
+ setTimeout(function () {
+ t.deepEqual(resources, [
+ { id : 0 },
+ { id : 1 },
+ { id : 0 },
+ { id : 1 },
+ { id : 0 },
+ { id : 1 },
+ { id : 0 },
+ { id : 1 },
+ { id : 0 },
+ { id : 1 },
+ ]);
+ t.end();
+ }, 150);
+});

0 comments on commit 0df63f8

Please sign in to comment.