diff --git a/services/clsi/app/js/LocalCommandRunner.js b/services/clsi/app/js/LocalCommandRunner.js index ce274733585..aa62825443c 100644 --- a/services/clsi/app/js/LocalCommandRunner.js +++ b/services/clsi/app/js/LocalCommandRunner.js @@ -54,6 +54,7 @@ module.exports = CommandRunner = { cwd: directory, env, stdio: ['pipe', 'pipe', 'ignore'], + detached: true, }) let stdout = '' diff --git a/services/clsi/test/acceptance/js/StopCompile.js b/services/clsi/test/acceptance/js/StopCompile.js new file mode 100644 index 00000000000..103a70f37d7 --- /dev/null +++ b/services/clsi/test/acceptance/js/StopCompile.js @@ -0,0 +1,47 @@ +const Client = require('./helpers/Client') +const ClsiApp = require('./helpers/ClsiApp') +const { expect } = require('chai') + +describe('Stop compile', function () { + before(function (done) { + this.request = { + options: { + timeout: 100, + }, // seconds + resources: [ + { + path: 'main.tex', + content: `\ +\\documentclass{article} +\\begin{document} +\\def\\x{Hello!\\par\\x} +\\x +\\end{document}\ +`, + }, + ], + } + this.project_id = Client.randomId() + ClsiApp.ensureRunning(() => { + // start the compile in the background + Client.compile(this.project_id, this.request, (error, res, body) => { + this.compileResult = { error, res, body } + }) + // wait for 1 second before stopping the compile + setTimeout(() => { + Client.stopCompile(this.project_id, (error, res, body) => { + this.stopResult = { error, res, body } + setTimeout(done, 1000) // allow time for the compile request to terminate + }) + }, 1000) + }) + }) + + it('should force a compile response with an error status', function () { + expect(this.stopResult.error).to.be.null + expect(this.stopResult.res.statusCode).to.equal(204) + expect(this.compileResult.res.statusCode).to.equal(200) + expect(this.compileResult.body.compile.status).to.equal('terminated') + expect(this.compileResult.body.compile.error).to.equal('terminated') + }) +}) diff --git a/services/clsi/test/acceptance/js/helpers/Client.js b/services/clsi/test/acceptance/js/helpers/Client.js index a0bdce734f3..49bf7390c6f 100644 --- a/services/clsi/test/acceptance/js/helpers/Client.js +++ b/services/clsi/test/acceptance/js/helpers/Client.js @@ -42,6 +42,16 @@ module.exports = Client = { ) }, + stopCompile(projectId, callback) { + if (callback == null) { + callback = function () {} + } + return request.post( + { url: `${this.host}/project/${projectId}/compile/stop` }, + callback + ) + }, + clearCache(projectId, callback) { if (callback == null) { callback = function () {}