CheckingTheLock.coffee 1004 B

123456789101112131415161718192021222324252627282930313233343536
  1. require('coffee-script')
  2. sinon = require('sinon')
  3. assert = require('assert')
  4. path = require('path')
  5. modulePath = path.join __dirname, '../../../../app/js/LockManager.js'
  6. project_id = 1234
  7. doc_id = 5678
  8. blockingKey = "Blocking:#{doc_id}"
  9. SandboxedModule = require('sandboxed-module')
  10. describe 'LockManager - checking the lock', ()->
  11. existsStub = sinon.stub()
  12. mocks =
  13. "logger-sharelatex": log:->
  14. "./RedisKeyBuilder":
  15. blockingKey: ({doc_id}) -> "Blocking:#{doc_id}"
  16. "./RedisBackend":
  17. createClient : ()->
  18. auth:->
  19. exists: existsStub
  20. "./Metrics": {inc: () ->}
  21. LockManager = SandboxedModule.require(modulePath, requires: mocks)
  22. it 'should return true if the key does not exists', (done)->
  23. existsStub.yields(null, "0")
  24. LockManager.checkLock doc_id, (err, free)->
  25. free.should.equal true
  26. done()
  27. it 'should return false if the key does exists', (done)->
  28. existsStub.yields(null, "1")
  29. LockManager.checkLock doc_id, (err, free)->
  30. free.should.equal false
  31. done()