From 9e0ad7c0b14fbd017dc6be61e792bf69dd54e8fa Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Wed, 22 Jun 2011 12:03:05 +0100 Subject: Add tests for the external_command library, and fix a bug (which was actually a fairly late regression, showing the benefits of formal tests vs informal testing). I believe this bug was the cause of the recent Xapian indexing errors. --- lib/external_command.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/external_command.rb') diff --git a/lib/external_command.rb b/lib/external_command.rb index de8bfc11e..96292854f 100644 --- a/lib/external_command.rb +++ b/lib/external_command.rb @@ -104,20 +104,24 @@ class ExternalCommand @fhs = {@out_read => @out, @err_read => @err, @fin_read => @fin} while @fin.empty? - r = read_data - if r.nil? + ok = read_data + if !ok raise "select() timed out even with a nil (infinite) timeout" end end + while read_data(0) + # Pull out any data that’s left in the pipes + end + Process::waitpid(@pid) @status = @fin.to_i @out_read.close @err_read.close end - def read_data() - ready_array = IO.select(@fhs.keys, [], [], nil) + def read_data(timeout=nil) + ready_array = IO.select(@fhs.keys, [], [], timeout) return false if ready_array.nil? ready_array[0].each do |fh| begin -- cgit v1.2.3