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'
|
|
|
|
project_id = 1234
|
|
|
|
doc_id = 5678
|
2014-05-14 09:16:27 -04:00
|
|
|
SandboxedModule = require('sandboxed-module')
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
describe 'LockManager - releasing the lock', ()->
|
|
|
|
|
2016-04-13 06:59:56 -04:00
|
|
|
evalStub = sinon.stub().yields(1)
|
2014-02-12 05:40:42 -05:00
|
|
|
mocks =
|
|
|
|
"logger-sharelatex": log:->
|
2016-06-07 12:58:18 -04:00
|
|
|
"./RedisKeyBuilder":
|
|
|
|
blockingKey: ({doc_id}) -> "Blocking:#{doc_id}"
|
|
|
|
"./RedisBackend":
|
2014-02-12 05:40:42 -05:00
|
|
|
createClient : ()->
|
|
|
|
auth:->
|
2016-04-13 06:59:56 -04:00
|
|
|
eval: evalStub
|
2016-01-20 12:36:06 -05:00
|
|
|
"./Metrics": {inc: () ->}
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2014-05-14 09:16:27 -04:00
|
|
|
LockManager = SandboxedModule.require(modulePath, requires: mocks)
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
it 'should put a all data into memory', (done)->
|
2016-04-13 06:59:56 -04:00
|
|
|
lockValue = "lock-value-stub"
|
|
|
|
LockManager.releaseLock doc_id, lockValue, ->
|
|
|
|
evalStub.calledWith(LockManager.unlockScript, 1, "Blocking:#{doc_id}", lockValue).should.equal true
|
2014-02-12 05:40:42 -05:00
|
|
|
done()
|
|
|
|
|