ReleasingTheLock.test.mjs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. import sinon from 'sinon'
  13. import path from 'node:path'
  14. import { vi } from 'vitest'
  15. const modulePath = path.join(
  16. import.meta.dirname,
  17. '../../../../../app/src/infrastructure/LockManager.mjs'
  18. )
  19. const lockKey = `lock:web:{${5678}}`
  20. const lockValue = '123456'
  21. describe('LockManager - releasing the lock', function () {
  22. let LockManager
  23. const deleteStub = sinon.stub().callsArgWith(4)
  24. beforeEach(async function () {
  25. vi.doMock('@overleaf/settings', () => ({
  26. default: {
  27. redis: {},
  28. lockManager: {
  29. lockTestInterval: 50,
  30. maxTestInterval: 1000,
  31. maxLockWaitTime: 10000,
  32. redisLockExpiry: 30,
  33. slowExecutionThreshold: 5000,
  34. },
  35. },
  36. }))
  37. vi.doMock('../../../../../app/src/infrastructure/RedisWrapper', () => ({
  38. default: {
  39. client() {
  40. return {
  41. auth() {},
  42. eval: deleteStub,
  43. }
  44. },
  45. },
  46. }))
  47. LockManager = (await import(modulePath)).default
  48. LockManager.unlockScript = 'this is the unlock script'
  49. })
  50. it('should put all data into memory', async function () {
  51. await new Promise(resolve => {
  52. return LockManager._releaseLock(lockKey, lockValue, () => {
  53. deleteStub
  54. .calledWith(LockManager.unlockScript, 1, lockKey, lockValue)
  55. .should.equal(true)
  56. return resolve()
  57. })
  58. })
  59. })
  60. })