CheckingTheLock.coffee 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. sinon = require('sinon')
  2. assert = require('assert')
  3. path = require('path')
  4. modulePath = path.join __dirname, '../../../../../app/js/infrastructure/LockManager.js'
  5. lockKey = "lock:web:{#{5678}}"
  6. SandboxedModule = require('sandboxed-module')
  7. describe 'LockManager - checking the lock', ()->
  8. existsStub = sinon.stub()
  9. setStub = sinon.stub()
  10. exireStub = sinon.stub()
  11. execStub = sinon.stub()
  12. mocks =
  13. "logger-sharelatex": log:->
  14. "./RedisWrapper":
  15. client: ()->
  16. auth:->
  17. multi: ->
  18. exists: existsStub
  19. expire: exireStub
  20. set: setStub
  21. exec: execStub
  22. LockManager = SandboxedModule.require(modulePath, requires: mocks)
  23. it 'should check if lock exists but not set or expire', (done)->
  24. execStub.callsArgWith(0, null, ["1"])
  25. LockManager._checkLock lockKey, (err, docIsLocked)->
  26. existsStub.calledWith(lockKey).should.equal true
  27. setStub.called.should.equal false
  28. exireStub.called.should.equal false
  29. done()
  30. it 'should return true if the key does not exists', (done)->
  31. execStub.callsArgWith(0, null, "0")
  32. LockManager._checkLock lockKey, (err, free)->
  33. free.should.equal true
  34. done()
  35. it 'should return false if the key does exists', (done)->
  36. execStub.callsArgWith(0, null, "1")
  37. LockManager._checkLock lockKey, (err, free)->
  38. free.should.equal false
  39. done()