ReleasingTheLock.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* eslint-disable
  2. max-len,
  3. no-unused-vars,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. const sinon = require('sinon')
  13. const assert = require('assert')
  14. const path = require('path')
  15. const modulePath = path.join(
  16. __dirname,
  17. '../../../../../app/src/infrastructure/LockManager.js'
  18. )
  19. const lockKey = `lock:web:{${5678}}`
  20. const lockValue = '123456'
  21. const SandboxedModule = require('sandboxed-module')
  22. describe('LockManager - releasing the lock', function () {
  23. const deleteStub = sinon.stub().callsArgWith(4)
  24. const mocks = {
  25. '@overleaf/settings': {
  26. redis: {},
  27. lockManager: {
  28. lockTestInterval: 50,
  29. maxTestInterval: 1000,
  30. maxLockWaitTime: 10000,
  31. redisLockExpiry: 30,
  32. slowExecutionThreshold: 5000,
  33. },
  34. },
  35. '@overleaf/metrics': {},
  36. './RedisWrapper': {
  37. client() {
  38. return {
  39. auth() {},
  40. eval: deleteStub,
  41. }
  42. },
  43. },
  44. }
  45. const LockManager = SandboxedModule.require(modulePath, { requires: mocks })
  46. LockManager.unlockScript = 'this is the unlock script'
  47. it('should put a all data into memory', function (done) {
  48. return LockManager._releaseLock(lockKey, lockValue, () => {
  49. deleteStub
  50. .calledWith(LockManager.unlockScript, 1, lockKey, lockValue)
  51. .should.equal(true)
  52. return done()
  53. })
  54. })
  55. })