From b45aca072f9be66ea5a7f59c11b6731edfff2625 Mon Sep 17 00:00:00 2001 From: ronen barzel Date: Mon, 4 Feb 2013 09:47:59 +0000 Subject: [PATCH] Bug fix: coverage hangs for large files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code that used IO.pipe & ChildProcess to run istanbul was waiting for the process to finish before reading the result.  With a file whose instrumentation is large enough to exceed the system IO buffer size, the istanbul process would block and we'd have deadlock.  Rather than fixing that using the appropriate nonblocking reading, just switched to %x[] --- lib/guard/jasmine/coverage.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/guard/jasmine/coverage.rb b/lib/guard/jasmine/coverage.rb index 9ffbc3a..683eaf1 100644 --- a/lib/guard/jasmine/coverage.rb +++ b/lib/guard/jasmine/coverage.rb @@ -26,16 +26,12 @@ def evaluate(context, locals) File.write input, data - r, w = IO.pipe - proc = ChildProcess.build(JasmineCoverage.coverage_bin, 'instrument', '--embed-source', input) - proc.io.stdout = proc.io.stderr = w - proc.start - proc.wait - w.close + result = %x[#{JasmineCoverage.coverage_bin} instrument --embed-source #{input.shellescape}] - raise "Could not generate coverage instrumented file for #{ file }" unless proc.exit_code == 0 + raise "Could not generate coverage instrumented file for #{ file }" unless $?.exitstatus == 0 + + result.gsub input, file - r.read.gsub input, file end end