LockManagerTests.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* eslint-disable
  2. no-return-assign,
  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 SandboxedModule = require('sandboxed-module')
  13. const sinon = require('sinon')
  14. const modulePath = require('path').join(
  15. __dirname,
  16. '../../../app/js/LockManager'
  17. )
  18. const Path = require('path')
  19. const Errors = require('../../../app/js/Errors')
  20. describe('DockerLockManager', function () {
  21. beforeEach(function () {
  22. this.LockManager = SandboxedModule.require(modulePath, {
  23. requires: {
  24. '@overleaf/settings': {},
  25. fs: {
  26. lstat: sinon.stub().callsArgWith(1),
  27. readdir: sinon.stub().callsArgWith(1),
  28. },
  29. lockfile: (this.Lockfile = {}),
  30. },
  31. })
  32. return (this.lockFile = '/local/compile/directory/.project-lock')
  33. })
  34. return describe('runWithLock', function () {
  35. beforeEach(function () {
  36. this.runner = sinon.stub().callsArgWith(0, null, 'foo', 'bar')
  37. return (this.callback = sinon.stub())
  38. })
  39. describe('normally', function () {
  40. beforeEach(function () {
  41. this.Lockfile.lock = sinon.stub().callsArgWith(2, null)
  42. this.Lockfile.unlock = sinon.stub().callsArgWith(1, null)
  43. return this.LockManager.runWithLock(
  44. this.lockFile,
  45. this.runner,
  46. this.callback
  47. )
  48. })
  49. it('should run the compile', function () {
  50. return this.runner.calledWith().should.equal(true)
  51. })
  52. return it('should call the callback with the response from the compile', function () {
  53. return this.callback
  54. .calledWithExactly(null, 'foo', 'bar')
  55. .should.equal(true)
  56. })
  57. })
  58. return describe('when the project is locked', function () {
  59. beforeEach(function () {
  60. this.error = new Error()
  61. this.error.code = 'EEXIST'
  62. this.Lockfile.lock = sinon.stub().callsArgWith(2, this.error)
  63. this.Lockfile.unlock = sinon.stub().callsArgWith(1, null)
  64. return this.LockManager.runWithLock(
  65. this.lockFile,
  66. this.runner,
  67. this.callback
  68. )
  69. })
  70. it('should not run the compile', function () {
  71. return this.runner.called.should.equal(false)
  72. })
  73. it('should return an error', function () {
  74. this.callback
  75. .calledWithExactly(sinon.match(Errors.AlreadyCompilingError))
  76. .should.equal(true)
  77. })
  78. })
  79. })
  80. })