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
|
|
|
|
2016-04-13 06:59:56 -04:00
|
|
|
describe 'LockManager - checking the lock', ()->
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
existsStub = 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:->
|
2016-04-13 06:59:56 -04:00
|
|
|
exists: existsStub
|
2016-01-20 12:36:06 -05:00
|
|
|
"./Metrics": {inc: () ->}
|
2014-05-14 09:16:27 -04:00
|
|
|
LockManager = SandboxedModule.require(modulePath, requires: mocks)
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
it 'should return true if the key does not exists', (done)->
|
2016-04-13 06:59:56 -04:00
|
|
|
existsStub.yields(null, "0")
|
2014-02-12 05:40:42 -05:00
|
|
|
LockManager.checkLock doc_id, (err, free)->
|
|
|
|
free.should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should return false if the key does exists', (done)->
|
2016-04-13 06:59:56 -04:00
|
|
|
existsStub.yields(null, "1")
|
2014-02-12 05:40:42 -05:00
|
|
|
LockManager.checkLock doc_id, (err, free)->
|
|
|
|
free.should.equal false
|
|
|
|
done()
|