Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added mocha options file and LockQueueTest

  • Loading branch information...
commit 34d5bfc325d52b96d6a70354a1cb40ba6051f10f 1 parent 67a082b
@bobrik authored
Showing with 76 additions and 0 deletions.
  1. +74 −0 test/LockQueueTest.js
  2. +2 −0  test/mocha.opts
View
74 test/LockQueueTest.js
@@ -0,0 +1,74 @@
+(function(module) {
+ var assert = require("assert"),
+ LockQueue = require("../lib/LockQueue"),
+ Lock = require("../lib/Lock"),
+ queueName = "pewpewpew";
+
+ suite("LockQueue", function() {
+ function makeLockWaiting(lock) {
+ lock.isWaiting = function() {
+ return true;
+ }
+
+ return lock;
+ }
+
+ suite("LockQueue::push", function() {
+ var queue = new LockQueue(queueName);
+
+ test("LockQueue::push should only accept instances of Lock", function(done) {
+ queue.push(queue, function(error) {
+ assert.ok(error);
+ done();
+ });
+ });
+
+ test("LockQueue::push should not accept not waiting locks", function(done) {
+ var badLock = new LockQueue(queueName);
+
+ queue.push(badLock, function(error) {
+ assert.ok(error);
+ done();
+ });
+ });
+
+ test("LockQueue::push should only accept locks with the same name", function(done) {
+ var badLock = makeLockWaiting(new LockQueue(queueName + queueName));
+
+ queue.push(badLock, function(error) {
+ assert.ok(error);
+ done();
+ });
+ });
+ });
+
+ suite("LockQueue::length", function() {
+ var queue = new LockQueue(queueName);
+
+ test("LockQueue length getter is zero with empty queue", function(done) {
+ assert.equal(queue.length, 0);
+ done();
+ });
+
+ test("LockQueue size should be 1 after lock adding", function(done) {
+ var lock = makeLockWaiting(new Lock(queue.getName()));
+
+ queue.push(lock, function(error) {
+ assert.ok(!error);
+ assert.equal(queue.length, 1);
+ done();
+ });
+ });
+ });
+
+ suite("Lock::getName", function() {
+ test("Lock::name should return name that was passed to the constructor", function(done) {
+ var queue = new LockQueue(queueName);
+
+ assert.equal(queue.getName(), queueName);
+
+ done();
+ });
+ });
+ });
+})(module);
View
2  test/mocha.opts
@@ -0,0 +1,2 @@
+--ui tdd
+--reporter spec
Please sign in to comment.
Something went wrong with that request. Please try again.