2020-02-19 06:15:25 -05: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 06:15:08 -05: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 06:15:37 -05:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const sinon = require('sinon')
|
2021-05-19 06:17:08 -04:00
|
|
|
const { expect } = require('chai')
|
2020-02-19 06:15:37 -05:00
|
|
|
const modulePath = require('path').join(
|
|
|
|
__dirname,
|
|
|
|
'../../../app/js/LatexRunner'
|
|
|
|
)
|
|
|
|
const Path = require('path')
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('LatexRunner', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
let Timer
|
|
|
|
this.LatexRunner = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
2021-07-12 12:47:21 -04:00
|
|
|
'@overleaf/settings': (this.Settings = {
|
2020-02-19 06:15:37 -05:00
|
|
|
docker: {
|
2021-07-13 07:04:48 -04:00
|
|
|
socketPath: '/var/run/docker.sock',
|
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
}),
|
|
|
|
'./Metrics': {
|
|
|
|
Timer: (Timer = class Timer {
|
|
|
|
done() {}
|
2021-07-13 07:04:48 -04:00
|
|
|
}),
|
2020-02-19 06:15:37 -05:00
|
|
|
},
|
2020-05-20 06:52:53 -04:00
|
|
|
'./CommandRunner': (this.CommandRunner = {}),
|
2020-06-02 04:18:38 -04:00
|
|
|
fs: (this.fs = {
|
2021-07-13 07:04:48 -04:00
|
|
|
writeFile: sinon.stub().callsArg(2),
|
|
|
|
}),
|
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-02-19 06:15:37 -05:00
|
|
|
this.directory = '/local/compile/directory'
|
|
|
|
this.mainFile = 'main-file.tex'
|
|
|
|
this.compiler = 'pdflatex'
|
|
|
|
this.image = 'example.com/image'
|
2020-06-11 11:01:44 -04:00
|
|
|
this.compileGroup = 'compile-group'
|
2020-02-19 06:15:37 -05:00
|
|
|
this.callback = sinon.stub()
|
|
|
|
this.project_id = 'project-id-123'
|
|
|
|
return (this.env = { foo: '123' })
|
|
|
|
})
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return describe('runLatex', function () {
|
|
|
|
beforeEach(function () {
|
2020-06-11 11:01:44 -04:00
|
|
|
return (this.CommandRunner.run = sinon.stub().callsArgWith(7, null, {
|
2020-06-02 06:12:57 -04:00
|
|
|
stdout: 'this is stdout',
|
2021-07-13 07:04:48 -04:00
|
|
|
stderr: 'this is stderr',
|
2020-06-02 06:12:57 -04:00
|
|
|
}))
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('normally', function () {
|
2021-05-19 06:17:08 -04:00
|
|
|
beforeEach(function (done) {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.LatexRunner.runLatex(
|
|
|
|
this.project_id,
|
|
|
|
{
|
|
|
|
directory: this.directory,
|
|
|
|
mainFile: this.mainFile,
|
|
|
|
compiler: this.compiler,
|
|
|
|
timeout: (this.timeout = 42000),
|
|
|
|
image: this.image,
|
2020-06-11 11:01:44 -04:00
|
|
|
environment: this.env,
|
2021-07-13 07:04:48 -04:00
|
|
|
compileGroup: this.compileGroup,
|
2020-02-19 06:15:37 -05:00
|
|
|
},
|
2021-05-19 06:17:08 -04:00
|
|
|
(error, output, stats, timings) => {
|
|
|
|
this.timings = timings
|
|
|
|
done(error)
|
|
|
|
}
|
2020-02-19 06:15:37 -05:00
|
|
|
)
|
|
|
|
})
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should run the latex command', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.CommandRunner.run
|
|
|
|
.calledWith(
|
|
|
|
this.project_id,
|
|
|
|
sinon.match.any,
|
|
|
|
this.directory,
|
|
|
|
this.image,
|
|
|
|
this.timeout,
|
2020-06-11 11:01:44 -04:00
|
|
|
this.env,
|
|
|
|
this.compileGroup
|
2020-02-19 06:15:37 -05:00
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
2020-05-20 06:52:53 -04:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should record the stdout and stderr', function () {
|
2020-05-20 06:52:53 -04:00
|
|
|
this.fs.writeFile
|
2020-06-02 04:18:38 -04:00
|
|
|
.calledWith(this.directory + '/' + 'output.stdout', 'this is stdout')
|
2020-05-20 06:52:53 -04:00
|
|
|
.should.equal(true)
|
|
|
|
this.fs.writeFile
|
2020-06-02 04:18:38 -04:00
|
|
|
.calledWith(this.directory + '/' + 'output.stderr', 'this is stderr')
|
2020-05-20 06:52:53 -04:00
|
|
|
.should.equal(true)
|
|
|
|
})
|
2021-05-19 06:17:08 -04:00
|
|
|
|
|
|
|
it('should not record cpu metrics', function () {
|
|
|
|
expect(this.timings['cpu-percent']).to.not.exist
|
|
|
|
expect(this.timings['cpu-time']).to.not.exist
|
|
|
|
expect(this.timings['sys-time']).to.not.exist
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with time -v', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
this.CommandRunner.run = sinon.stub().callsArgWith(7, null, {
|
|
|
|
stdout: 'this is stdout',
|
|
|
|
stderr:
|
|
|
|
'\tCommand being timed: "sh -c timeout 1 yes > /dev/null"\n' +
|
|
|
|
'\tUser time (seconds): 0.28\n' +
|
|
|
|
'\tSystem time (seconds): 0.70\n' +
|
2021-07-13 07:04:48 -04:00
|
|
|
'\tPercent of CPU this job got: 98%\n',
|
2021-05-19 06:17:08 -04:00
|
|
|
})
|
|
|
|
this.LatexRunner.runLatex(
|
|
|
|
this.project_id,
|
|
|
|
{
|
|
|
|
directory: this.directory,
|
|
|
|
mainFile: this.mainFile,
|
|
|
|
compiler: this.compiler,
|
|
|
|
timeout: (this.timeout = 42000),
|
|
|
|
image: this.image,
|
|
|
|
environment: this.env,
|
2021-07-13 07:04:48 -04:00
|
|
|
compileGroup: this.compileGroup,
|
2021-05-19 06:17:08 -04:00
|
|
|
},
|
|
|
|
(error, output, stats, timings) => {
|
|
|
|
this.timings = timings
|
|
|
|
done(error)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should record cpu metrics', function () {
|
|
|
|
expect(this.timings['cpu-percent']).to.equal(98)
|
|
|
|
expect(this.timings['cpu-time']).to.equal(0.28)
|
|
|
|
expect(this.timings['sys-time']).to.equal(0.7)
|
|
|
|
})
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('with an .Rtex main file', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.LatexRunner.runLatex(
|
|
|
|
this.project_id,
|
|
|
|
{
|
|
|
|
directory: this.directory,
|
|
|
|
mainFile: 'main-file.Rtex',
|
|
|
|
compiler: this.compiler,
|
|
|
|
image: this.image,
|
2021-07-13 07:04:48 -04:00
|
|
|
timeout: (this.timeout = 42000),
|
2020-02-19 06:15:37 -05:00
|
|
|
},
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should run the latex command on the equivalent .tex file', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
const command = this.CommandRunner.run.args[0][1]
|
|
|
|
const mainFile = command.slice(-1)[0]
|
|
|
|
return mainFile.should.equal('$COMPILE_DIR/main-file.tex')
|
|
|
|
})
|
|
|
|
})
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return describe('with a flags option', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
return this.LatexRunner.runLatex(
|
|
|
|
this.project_id,
|
|
|
|
{
|
|
|
|
directory: this.directory,
|
|
|
|
mainFile: this.mainFile,
|
|
|
|
compiler: this.compiler,
|
|
|
|
image: this.image,
|
|
|
|
timeout: (this.timeout = 42000),
|
2021-07-13 07:04:48 -04:00
|
|
|
flags: ['-file-line-error', '-halt-on-error'],
|
2020-02-19 06:15:37 -05:00
|
|
|
},
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
2019-05-10 11:51:40 -04:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
return it('should include the flags in the command', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
const command = this.CommandRunner.run.args[0][1]
|
|
|
|
const flags = command.filter(
|
2021-07-13 07:04:48 -04:00
|
|
|
arg => arg === '-file-line-error' || arg === '-halt-on-error'
|
2020-02-19 06:15:37 -05:00
|
|
|
)
|
|
|
|
flags.length.should.equal(2)
|
|
|
|
flags[0].should.equal('-file-line-error')
|
|
|
|
return flags[1].should.equal('-halt-on-error')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|