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