2020-02-19 11:15:25 +00:00
|
|
|
/* eslint-disable
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-19 11:15:08 +00:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-02-19 11:15:37 +00:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const sinon = require('sinon')
|
|
|
|
const modulePath = require('path').join(
|
|
|
|
__dirname,
|
|
|
|
'../../../app/js/LockManager'
|
|
|
|
)
|
|
|
|
const Path = require('path')
|
|
|
|
const Errors = require('../../../app/js/Errors')
|
2020-02-19 11:15:08 +00:00
|
|
|
|
2020-08-10 16:01:11 +00:00
|
|
|
describe('DockerLockManager', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 11:15:37 +00:00
|
|
|
this.LockManager = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
|
|
|
'settings-sharelatex': {},
|
|
|
|
fs: {
|
|
|
|
lstat: sinon.stub().callsArgWith(1),
|
|
|
|
readdir: sinon.stub().callsArgWith(1)
|
|
|
|
},
|
|
|
|
lockfile: (this.Lockfile = {})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return (this.lockFile = '/local/compile/directory/.project-lock')
|
|
|
|
})
|
2020-02-19 11:15:08 +00:00
|
|
|
|
2020-08-10 16:01:11 +00:00
|
|
|
return describe('runWithLock', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 11:15:37 +00:00
|
|
|
this.runner = sinon.stub().callsArgWith(0, null, 'foo', 'bar')
|
|
|
|
return (this.callback = sinon.stub())
|
|
|
|
})
|
2020-02-19 11:15:08 +00:00
|
|
|
|
2020-08-10 16:01:11 +00:00
|
|
|
describe('normally', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 11:15:37 +00:00
|
|
|
this.Lockfile.lock = sinon.stub().callsArgWith(2, null)
|
|
|
|
this.Lockfile.unlock = sinon.stub().callsArgWith(1, null)
|
|
|
|
return this.LockManager.runWithLock(
|
|
|
|
this.lockFile,
|
|
|
|
this.runner,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
2020-02-19 11:15:08 +00:00
|
|
|
|
2020-08-10 16:01:11 +00:00
|
|
|
it('should run the compile', function () {
|
2020-02-19 11:15:37 +00:00
|
|
|
return this.runner.calledWith().should.equal(true)
|
|
|
|
})
|
2017-09-22 15:19:33 +00:00
|
|
|
|
2020-08-10 16:01:11 +00:00
|
|
|
return it('should call the callback with the response from the compile', function () {
|
2020-02-19 11:15:37 +00:00
|
|
|
return this.callback
|
|
|
|
.calledWithExactly(null, 'foo', 'bar')
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
2020-02-19 11:15:08 +00:00
|
|
|
|
2020-08-10 16:01:11 +00:00
|
|
|
return describe('when the project is locked', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 11:15:37 +00:00
|
|
|
this.error = new Error()
|
|
|
|
this.error.code = 'EEXIST'
|
|
|
|
this.Lockfile.lock = sinon.stub().callsArgWith(2, this.error)
|
|
|
|
this.Lockfile.unlock = sinon.stub().callsArgWith(1, null)
|
|
|
|
return this.LockManager.runWithLock(
|
|
|
|
this.lockFile,
|
|
|
|
this.runner,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
2020-02-19 11:15:08 +00:00
|
|
|
|
2020-08-10 16:01:11 +00:00
|
|
|
it('should not run the compile', function () {
|
2020-02-19 11:15:37 +00:00
|
|
|
return this.runner.called.should.equal(false)
|
|
|
|
})
|
2017-09-22 15:19:33 +00:00
|
|
|
|
2020-08-10 16:01:11 +00:00
|
|
|
it('should return an error', function () {
|
2020-03-12 09:35:11 +00:00
|
|
|
this.callback
|
|
|
|
.calledWithExactly(sinon.match(Errors.AlreadyCompilingError))
|
|
|
|
.should.equal(true)
|
2020-02-19 11:15:37 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|