improve error handling of releaseLock

ported from docupdater
This commit is contained in:
Brian Gough
2017-03-31 15:17:13 +01:00
parent 5989d8f27f
commit b0b05d1e1b
2 changed files with 30 additions and 1 deletions
@@ -15,6 +15,7 @@ describe "LockManager", ->
createClient: () => @rclient =
auth: sinon.stub()
"settings-sharelatex": @Settings
"logger-sharelatex": {error: ->}
@key = "lock-key"
@callback = sinon.stub()
@@ -174,3 +175,24 @@ describe "LockManager", ->
it "should call the callback with the error", ->
@callback.calledWith(@error).should.equal true
describe "releaseLock", ->
describe "when the lock is current", ->
beforeEach ->
@rclient.eval = sinon.stub().yields(null, 1)
@LockManager.releaseLock @key, @lockValue, @callback
it 'should clear the data from redis', ->
@rclient.eval.calledWith(@LockManager.unlockScript, 1, @key, @lockValue).should.equal true
it 'should call the callback', ->
@callback.called.should.equal true
describe "when the lock has expired", ->
beforeEach ->
@rclient.eval = sinon.stub().yields(null, 0)
@LockManager.releaseLock @key, @lockValue, @callback
it 'should return an error if the lock has expired', ->
@callback.calledWith(new Error("tried to release timed out lock")).should.equal true