CheckingTheLock.coffee 932 B

12345678910111213141516171819202122232425262728293031323334
  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. "redis-sharelatex":
  15. createClient : ()->
  16. auth:->
  17. exists: existsStub
  18. "./Metrics": {inc: () ->}
  19. LockManager = SandboxedModule.require(modulePath, requires: mocks)
  20. it 'should return true if the key does not exists', (done)->
  21. existsStub.yields(null, "0")
  22. LockManager.checkLock doc_id, (err, free)->
  23. free.should.equal true
  24. done()
  25. it 'should return false if the key does exists', (done)->
  26. existsStub.yields(null, "1")
  27. LockManager.checkLock doc_id, (err, free)->
  28. free.should.equal false
  29. done()