Skip to content

Commit

Permalink
issue65: fixing a bug with unlocking an expired resource
Browse files Browse the repository at this point in the history
  • Loading branch information
grigoriy.nitsenko committed Jun 23, 2020
1 parent e90e80a commit f9f2e6a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
2 changes: 1 addition & 1 deletion redlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ Redlock.prototype.unlock = function unlock(lock, callback) {
// - It may hava already been manually released;
// - It may have expired;

if(response === resource.length || response === '' + resource.length)
if(response === 0 || response === '0' || response === resource.length || response === '' + resource.length)
votes++;

if(waiting-- > 1) return;
Expand Down
21 changes: 4 additions & 17 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ function test(name, clients){
});

it('should unlock an already-unlocked resource', function(done) {
assert(two, 'Could not run because a required previous test failed.');
two.unlock(function(err) {
assert.isNotNull(err)
done();
});
two.unlock(done);
});

it('should error when unable to fully release a resource', function(done) {
Expand Down Expand Up @@ -255,12 +251,9 @@ function test(name, clients){
});

it('should unlock an already-unlocked resource', function(done) {
assert(two, 'Could not run because a required previous test failed.');
two.unlock().done(function(result) {
done(new Error('Expected an error.'));
}, function(err) {
done();
});
}, done);
});

it('should error when unable to fully release a resource', function(done) {
Expand Down Expand Up @@ -499,11 +492,7 @@ function test(name, clients){
});

it('should unlock an already-unlocked multivalue resource', function(done) {
assert(two, 'Could not run because a required previous test failed.');
two.unlock(function(err) {
assert.isNotNull(err)
done();
});
two.unlock(done);
});

it('should error when unable to fully release a multivalue resource', function(done) {
Expand Down Expand Up @@ -646,10 +635,8 @@ function test(name, clients){
it('should unlock an already-unlocked multivalue resource', function(done) {
assert(two, 'Could not run because a required previous test failed.');
two.unlock().done(function(result) {
done(new Error('Expected an error.'));
}, function(err) {
done();
});
}, done);
});

it('should error when unable to fully release a multivalue resource', function(done) {
Expand Down

0 comments on commit f9f2e6a

Please sign in to comment.