2014-02-12 05:40:42 -05:00
|
|
|
require('coffee-script')
|
|
|
|
sinon = require('sinon')
|
|
|
|
assert = require('assert')
|
|
|
|
path = require('path')
|
|
|
|
modulePath = path.join __dirname, '../../../../app/js/LockManager.js'
|
|
|
|
keys = require(path.join __dirname, '../../../../app/js/RedisKeyBuilder.js')
|
|
|
|
project_id = 1234
|
|
|
|
doc_id = 5678
|
|
|
|
blockingKey = "Blocking:#{doc_id}"
|
2014-05-14 09:16:27 -04:00
|
|
|
SandboxedModule = require('sandboxed-module')
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
describe 'Lock Manager - checking the lock', ()->
|
|
|
|
|
|
|
|
existsStub = sinon.stub()
|
|
|
|
setStub = sinon.stub()
|
|
|
|
exireStub = sinon.stub()
|
|
|
|
execStub = sinon.stub()
|
|
|
|
|
|
|
|
mocks =
|
|
|
|
"logger-sharelatex": log:->
|
|
|
|
|
2014-10-07 07:08:36 -04:00
|
|
|
"redis-sharelatex":
|
2014-02-12 05:40:42 -05:00
|
|
|
createClient : ()->
|
|
|
|
auth:->
|
|
|
|
multi: ->
|
|
|
|
exists: existsStub
|
|
|
|
expire: exireStub
|
|
|
|
set: setStub
|
|
|
|
exec: execStub
|
2014-05-14 09:16:27 -04:00
|
|
|
LockManager = SandboxedModule.require(modulePath, requires: mocks)
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
it 'should check if lock exists but not set or expire', (done)->
|
|
|
|
execStub.callsArgWith(0, null, ["1"])
|
|
|
|
LockManager.checkLock doc_id, (err, docIsLocked)->
|
|
|
|
existsStub.calledWith(blockingKey).should.equal true
|
|
|
|
setStub.called.should.equal false
|
|
|
|
exireStub.called.should.equal false
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should return true if the key does not exists', (done)->
|
|
|
|
execStub.callsArgWith(0, null, "0")
|
|
|
|
LockManager.checkLock doc_id, (err, free)->
|
|
|
|
free.should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should return false if the key does exists', (done)->
|
|
|
|
execStub.callsArgWith(0, null, "1")
|
|
|
|
LockManager.checkLock doc_id, (err, free)->
|
|
|
|
free.should.equal false
|
|
|
|
done()
|