diff --git a/services/clsi/app.coffee b/services/clsi/app.coffee index 7f56d48ab9..ca93c706fe 100644 --- a/services/clsi/app.coffee +++ b/services/clsi/app.coffee @@ -13,12 +13,13 @@ ProjectPersistenceManager = require "./app/js/ProjectPersistenceManager" require("./app/js/db").sync() express = require "express" +bodyParser = require "body-parser" app = express() app.use Metrics.http.monitor(logger) -app.post "/project/:project_id/compile", express.bodyParser(), CompileController.compile -app.del "/project/:project_id", CompileController.clearCache +app.post "/project/:project_id/compile", bodyParser.json(limit: "2mb"), CompileController.compile +app.delete "/project/:project_id", CompileController.clearCache app.get "/project/:project_id/sync/code", CompileController.syncFromCode app.get "/project/:project_id/sync/pdf", CompileController.syncFromPdf diff --git a/services/clsi/app/coffee/CompileController.coffee b/services/clsi/app/coffee/CompileController.coffee index 090c3f09fc..cddb56b1ca 100644 --- a/services/clsi/app/coffee/CompileController.coffee +++ b/services/clsi/app/coffee/CompileController.coffee @@ -16,8 +16,11 @@ module.exports = CompileController = CompileManager.doCompile request, (error, outputFiles = []) -> if error? logger.error err: error, project_id: request.project_id, "error running compile" - error = error.message or error - status = "failure" + if error.timedout + status = "timedout" + else + status = "error" + code = 500 else status = "failure" for file in outputFiles @@ -25,10 +28,10 @@ module.exports = CompileController = status = "success" timer.done() - res.send JSON.stringify { + res.send (code or 200), { compile: status: status - error: error + error: error?.message or error outputFiles: outputFiles.map (file) -> url: "#{Settings.apis.clsi.url}/project/#{request.project_id}/output/#{file.path}" type: file.type diff --git a/services/clsi/package.json b/services/clsi/package.json index 6eb8e58729..14a0bc9947 100644 --- a/services/clsi/package.json +++ b/services/clsi/package.json @@ -5,7 +5,6 @@ "author": "James Allen ", "dependencies": { "async": "0.2.9", - "express": "3.3.1", "lynx": "0.0.11", "mkdirp": "0.3.5", "mysql": "2.0.0-alpha7", @@ -16,7 +15,9 @@ "sequelize": "~2.0.0-beta.2", "wrench": "~1.5.4", "smoke-test-sharelatex": "git+https://github.com/sharelatex/smoke-test-sharelatex.git#master", - "sqlite3": "~2.2.0" + "sqlite3": "~2.2.0", + "express": "^4.2.0", + "body-parser": "^1.2.0" }, "devDependencies": { "mocha": "1.10.0", diff --git a/services/clsi/test/acceptance/coffee/TimeoutTests.coffee b/services/clsi/test/acceptance/coffee/TimeoutTests.coffee index dd87e61458..66ac7a427a 100644 --- a/services/clsi/test/acceptance/coffee/TimeoutTests.coffee +++ b/services/clsi/test/acceptance/coffee/TimeoutTests.coffee @@ -22,6 +22,6 @@ describe "Timed out compile", -> it "should return a timeout error", -> @body.compile.error.should.equal "container timed out" - it "should return a failure status", -> - @body.compile.status.should.equal "failure" + it "should return a timedout status", -> + @body.compile.status.should.equal "timedout" diff --git a/services/clsi/test/unit/coffee/CompileControllerTests.coffee b/services/clsi/test/unit/coffee/CompileControllerTests.coffee index 2aefdb544a..d2babf7c2b 100644 --- a/services/clsi/test/unit/coffee/CompileControllerTests.coffee +++ b/services/clsi/test/unit/coffee/CompileControllerTests.coffee @@ -66,7 +66,7 @@ describe "CompileController", -> it "should return the JSON response", -> @res.send - .calledWith(JSON.stringify + .calledWith(200, compile: status: "success" error: null @@ -83,14 +83,46 @@ describe "CompileController", -> it "should return the JSON response with the error", -> @res.send - .calledWith(JSON.stringify + .calledWith(500, compile: - status: "failure" + status: "error" error: @message outputFiles: [] ) .should.equal true + describe "when the request times out", -> + beforeEach -> + @error = new Error(@message = "container timed out") + @error.timedout = true + @CompileManager.doCompile = sinon.stub().callsArgWith(1, @error, null) + @CompileController.compile @req, @res + + it "should return the JSON response with the timeout status", -> + @res.send + .calledWith(200, + compile: + status: "timedout" + error: @message + outputFiles: [] + ) + .should.equal true + + describe "when the request returns no output files", -> + beforeEach -> + @CompileManager.doCompile = sinon.stub().callsArgWith(1, null, []) + @CompileController.compile @req, @res + + it "should return the JSON response with the failure status", -> + @res.send + .calledWith(200, + compile: + error: null + status: "failure" + outputFiles: [] + ) + .should.equal true + describe "syncFromCode", -> beforeEach -> @file = "main.tex"