Browse Source

improve lock test

activeAddress
Ivan Socolsky 10 years ago
parent
commit
ba28f23506
  1. 19
      test/lock.js

19
test/lock.js

@ -8,24 +8,27 @@ var Lock = require('../lib/lock');
describe('Lock', function() { describe('Lock', function() {
it('should lock tasks using the same token', function(done) { it('should lock tasks using the same token', function(done) {
var i = 0; var a = false,
b = false;
Lock.get('123', function(lock) { Lock.get('123', function(lock) {
i++; a = true;
setTimeout(function() { setTimeout(function() {
lock.free(); lock.free();
}, 2); }, 5);
Lock.get('123', function(lock) { Lock.get('123', function(lock) {
i++; b = true;
lock.free(); lock.free();
}); });
}); });
setTimeout(function() { setTimeout(function() {
i.should.equal(1); a.should.equal(true);
b.should.equal(false);
}, 1); }, 1);
setTimeout(function() { setTimeout(function() {
i.should.equal(2); a.should.equal(true);
b.should.equal(true);
done(); done();
}, 3); }, 8);
}); });
it('should not lock tasks using different tokens', function(done) { it('should not lock tasks using different tokens', function(done) {
var i = 0; var i = 0;
@ -33,7 +36,7 @@ describe('Lock', function() {
i++; i++;
setTimeout(function() { setTimeout(function() {
lock.free(); lock.free();
}, 2); }, 5);
Lock.get('456', function(lock) { Lock.get('456', function(lock) {
i++; i++;
lock.free(); lock.free();

Loading…
Cancel
Save