Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

failing round robin test

  • Loading branch information...
commit 0df63f837004249a19b6767452b5208defd1bc3d 1 parent 8bae482
@substack authored
Showing with 35 additions and 0 deletions.
  1. +35 −0 test/round.js
View
35 test/round.js
@@ -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);
+});
Please sign in to comment.
Something went wrong with that request. Please try again.