2017-09-22 11:19:33 -04:00
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
sinon = require('sinon')
|
|
|
|
require('chai').should()
|
|
|
|
modulePath = require('path').join __dirname, '../../../app/js/LockManager'
|
|
|
|
Path = require "path"
|
|
|
|
Errors = require "../../../app/js/Errors"
|
|
|
|
|
2018-03-05 06:02:31 -05:00
|
|
|
describe "DockerLockManager", ->
|
2017-09-22 11:19:33 -04:00
|
|
|
beforeEach ->
|
|
|
|
@LockManager = SandboxedModule.require modulePath, requires:
|
|
|
|
"settings-sharelatex": {}
|
|
|
|
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
|
2018-08-22 16:32:19 -04:00
|
|
|
"fs":
|
|
|
|
lstat:sinon.stub().callsArgWith(1)
|
2017-09-22 11:19:33 -04:00
|
|
|
"lockfile": @Lockfile = {}
|
|
|
|
@lockFile = "/local/compile/directory/.project-lock"
|
|
|
|
|
|
|
|
describe "runWithLock", ->
|
|
|
|
beforeEach ->
|
|
|
|
@runner = sinon.stub().callsArgWith(0, null, "foo", "bar")
|
|
|
|
@callback = sinon.stub()
|
|
|
|
|
|
|
|
describe "normally", ->
|
|
|
|
beforeEach ->
|
|
|
|
@Lockfile.lock = sinon.stub().callsArgWith(2, null)
|
|
|
|
@Lockfile.unlock = sinon.stub().callsArgWith(1, null)
|
|
|
|
@LockManager.runWithLock @lockFile, @runner, @callback
|
|
|
|
|
|
|
|
it "should run the compile", ->
|
|
|
|
@runner
|
|
|
|
.calledWith()
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback with the response from the compile", ->
|
|
|
|
@callback
|
|
|
|
.calledWithExactly(null, "foo", "bar")
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
describe "when the project is locked", ->
|
|
|
|
beforeEach ->
|
|
|
|
@error = new Error()
|
|
|
|
@error.code = "EEXIST"
|
|
|
|
@Lockfile.lock = sinon.stub().callsArgWith(2,@error)
|
|
|
|
@Lockfile.unlock = sinon.stub().callsArgWith(1, null)
|
|
|
|
@LockManager.runWithLock @lockFile, @runner, @callback
|
|
|
|
|
|
|
|
it "should not run the compile", ->
|
|
|
|
@runner
|
|
|
|
.called
|
|
|
|
.should.equal false
|
|
|
|
|
|
|
|
it "should return an error", ->
|
|
|
|
error = new Errors.AlreadyCompilingError()
|
|
|
|
@callback
|
|
|
|
.calledWithExactly(error)
|
|
|
|
.should.equal true
|