mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 06:33:55 +01:00
improve error handling of releaseLock
ported from docupdater
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user