lock compile directory
This commit is contained in:
@@ -49,7 +49,7 @@ describe "CompileController", ->
|
||||
|
||||
describe "successfully", ->
|
||||
beforeEach ->
|
||||
@CompileManager.doCompile = sinon.stub().callsArgWith(1, null, @output_files)
|
||||
@CompileManager.doCompileWithLock = sinon.stub().callsArgWith(1, null, @output_files)
|
||||
@CompileController.compile @req, @res
|
||||
|
||||
it "should parse the request", ->
|
||||
@@ -58,7 +58,7 @@ describe "CompileController", ->
|
||||
.should.equal true
|
||||
|
||||
it "should run the compile for the specified project", ->
|
||||
@CompileManager.doCompile
|
||||
@CompileManager.doCompileWithLock
|
||||
.calledWith(@request_with_project_id)
|
||||
.should.equal true
|
||||
|
||||
@@ -84,7 +84,7 @@ describe "CompileController", ->
|
||||
|
||||
describe "with an error", ->
|
||||
beforeEach ->
|
||||
@CompileManager.doCompile = sinon.stub().callsArgWith(1, new Error(@message = "error message"), null)
|
||||
@CompileManager.doCompileWithLock = sinon.stub().callsArgWith(1, new Error(@message = "error message"), null)
|
||||
@CompileController.compile @req, @res
|
||||
|
||||
it "should return the JSON response with the error", ->
|
||||
@@ -102,7 +102,7 @@ describe "CompileController", ->
|
||||
beforeEach ->
|
||||
@error = new Error(@message = "container timed out")
|
||||
@error.timedout = true
|
||||
@CompileManager.doCompile = sinon.stub().callsArgWith(1, @error, null)
|
||||
@CompileManager.doCompileWithLock = sinon.stub().callsArgWith(1, @error, null)
|
||||
@CompileController.compile @req, @res
|
||||
|
||||
it "should return the JSON response with the timeout status", ->
|
||||
@@ -118,7 +118,7 @@ describe "CompileController", ->
|
||||
|
||||
describe "when the request returns no output files", ->
|
||||
beforeEach ->
|
||||
@CompileManager.doCompile = sinon.stub().callsArgWith(1, null, [])
|
||||
@CompileManager.doCompileWithLock = sinon.stub().callsArgWith(1, null, [])
|
||||
@CompileController.compile @req, @res
|
||||
|
||||
it "should return the JSON response with the failure status", ->
|
||||
|
||||
@@ -19,9 +19,50 @@ describe "CompileManager", ->
|
||||
"./CommandRunner": @CommandRunner = {}
|
||||
"./DraftModeManager": @DraftModeManager = {}
|
||||
"./TikzManager": @TikzManager = {}
|
||||
"./LockManager": @LockManager = {}
|
||||
"fs": @fs = {}
|
||||
@callback = sinon.stub()
|
||||
|
||||
describe "doCompileWithLock", ->
|
||||
beforeEach ->
|
||||
@request =
|
||||
resources: @resources = "mock-resources"
|
||||
project_id: @project_id = "project-id-123"
|
||||
user_id: @user_id = "1234"
|
||||
@output_files = ["foo", "bar"]
|
||||
@CompileManager.doCompile = sinon.stub().callsArgWith(1, null, @output_files)
|
||||
@LockManager.runWithLock = (lockFile, runner, callback) ->
|
||||
runner (err, result...) ->
|
||||
callback(err, result...)
|
||||
|
||||
describe "when the project is not locked", ->
|
||||
beforeEach ->
|
||||
@CompileManager.doCompileWithLock @request, @callback
|
||||
|
||||
it "should call doCompile with the request", ->
|
||||
@CompileManager.doCompile
|
||||
.calledWith(@request)
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback with the output files", ->
|
||||
@callback.calledWithExactly(null, @output_files)
|
||||
.should.equal true
|
||||
|
||||
describe "when the project is locked", ->
|
||||
beforeEach ->
|
||||
@error = new Error("locked")
|
||||
@LockManager.runWithLock = (lockFile, runner, callback) =>
|
||||
callback(@error)
|
||||
@CompileManager.doCompileWithLock @request, @callback
|
||||
|
||||
it "should not call doCompile with the request", ->
|
||||
@CompileManager.doCompile
|
||||
.called.should.equal false
|
||||
|
||||
it "should call the callback with the error", ->
|
||||
@callback.calledWithExactly(@error)
|
||||
.should.equal true
|
||||
|
||||
describe "doCompile", ->
|
||||
beforeEach ->
|
||||
@output_files = [{
|
||||
|
||||
54
test/unit/coffee/LockManager.coffee
Normal file
54
test/unit/coffee/LockManager.coffee
Normal file
@@ -0,0 +1,54 @@
|
||||
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"
|
||||
|
||||
describe "LockManager", ->
|
||||
beforeEach ->
|
||||
@LockManager = SandboxedModule.require modulePath, requires:
|
||||
"settings-sharelatex": {}
|
||||
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
|
||||
"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
|
||||
Reference in New Issue
Block a user