LockManagerTests.js 2.8 KB

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