Use simpler exec command with a timeout

This commit is contained in:
James Allen 2014-04-09 15:34:54 +01:00
parent b53fed1243
commit 52b22a41c8
2 changed files with 11 additions and 27 deletions

View file

@ -75,19 +75,10 @@ module.exports = CompileManager =
_runSynctex: (args, callback = (error, stdout) ->) -> _runSynctex: (args, callback = (error, stdout) ->) ->
bin_path = Path.resolve(__dirname + "/../../bin/synctex") bin_path = Path.resolve(__dirname + "/../../bin/synctex")
proc = child_process.spawn bin_path, args seconds = 1000
proc.on "error", callback child_process.execFile bin_path, args, timeout: 10 * seconds, (error, stdout, stderr) ->
return callback(error) if error?
stdout = "" callback(null, stdout)
proc.stdout.on "data", (chunk) -> stdout += chunk.toString()
stderr = ""
proc.stderr.on "data", (chunk) -> stderr += chunk.toString()
proc.on "close", (code) ->
if code == 0
return callback(null, stdout)
else
return callback(new Error("synctex failed: #{stderr}"))
_parseSynctexFromCodeOutput: (output) -> _parseSynctexFromCodeOutput: (output) ->
results = [] results = []

View file

@ -114,25 +114,20 @@ describe "CompileManager", ->
@line = 5 @line = 5
@column = 3 @column = 3
@file_name = "main.tex" @file_name = "main.tex"
@proc = new EventEmitter() @child_process.execFile = sinon.stub()
@proc.stdout = new EventEmitter()
@proc.stderr = new EventEmitter()
@child_process.spawn = sinon.stub().returns(@proc)
@Settings.path.synctexBaseDir = (project_id) => "#{@Settings.path.compilesDir}/#{@project_id}" @Settings.path.synctexBaseDir = (project_id) => "#{@Settings.path.compilesDir}/#{@project_id}"
describe "syncFromCode", -> describe "syncFromCode", ->
beforeEach -> beforeEach ->
@stdout = "NODE\t#{@page}\t#{@h}\t#{@v}\t#{@width}\t#{@height}\n" @child_process.execFile.callsArgWith(3, null, @stdout = "NODE\t#{@page}\t#{@h}\t#{@v}\t#{@width}\t#{@height}\n", "")
@CompileManager.syncFromCode @project_id, @file_name, @line, @column, @callback @CompileManager.syncFromCode @project_id, @file_name, @line, @column, @callback
@proc.stdout.emit "data", @stdout
@proc.emit "close", 0
it "should execute the synctex binary", -> it "should execute the synctex binary", ->
bin_path = Path.resolve(__dirname + "/../../../bin/synctex") bin_path = Path.resolve(__dirname + "/../../../bin/synctex")
synctex_path = "#{@Settings.path.compilesDir}/#{@project_id}/output.pdf" synctex_path = "#{@Settings.path.compilesDir}/#{@project_id}/output.pdf"
file_path = "#{@Settings.path.compilesDir}/#{@project_id}/#{@file_name}" file_path = "#{@Settings.path.compilesDir}/#{@project_id}/#{@file_name}"
@child_process.spawn @child_process.execFile
.calledWith(bin_path, ["code", synctex_path, file_path, @line, @column]) .calledWith(bin_path, ["code", synctex_path, file_path, @line, @column], timeout: 10000)
.should.equal true .should.equal true
it "should call the callback with the parsed output", -> it "should call the callback with the parsed output", ->
@ -148,16 +143,14 @@ describe "CompileManager", ->
describe "syncFromPdf", -> describe "syncFromPdf", ->
beforeEach -> beforeEach ->
@stdout = "NODE\t#{@Settings.path.compilesDir}/#{@project_id}/#{@file_name}\t#{@line}\t#{@column}\n" @child_process.execFile.callsArgWith(3, null, @stdout = "NODE\t#{@Settings.path.compilesDir}/#{@project_id}/#{@file_name}\t#{@line}\t#{@column}\n", "")
@CompileManager.syncFromPdf @project_id, @page, @h, @v, @callback @CompileManager.syncFromPdf @project_id, @page, @h, @v, @callback
@proc.stdout.emit "data", @stdout
@proc.emit "close", 0
it "should execute the synctex binary", -> it "should execute the synctex binary", ->
bin_path = Path.resolve(__dirname + "/../../../bin/synctex") bin_path = Path.resolve(__dirname + "/../../../bin/synctex")
synctex_path = "#{@Settings.path.compilesDir}/#{@project_id}/output.pdf" synctex_path = "#{@Settings.path.compilesDir}/#{@project_id}/output.pdf"
@child_process.spawn @child_process.execFile
.calledWith(bin_path, ["pdf", synctex_path, @page, @h, @v]) .calledWith(bin_path, ["pdf", synctex_path, @page, @h, @v], timeout: 10000)
.should.equal true .should.equal true
it "should call the callback with the parsed output", -> it "should call the callback with the parsed output", ->