LockManagerTests.js 2.5 KB

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