diff options
author | Robin Houston <robin@lenny.robin> | 2011-06-22 12:03:05 +0100 |
---|---|---|
committer | Robin Houston <robin@lenny.robin> | 2011-06-22 12:03:05 +0100 |
commit | 9e0ad7c0b14fbd017dc6be61e792bf69dd54e8fa (patch) | |
tree | c04e230c210b4539b91dafef1b60d144ed5613ff /lib/external_command.rb | |
parent | 6c12fe40c90ea37c3227b033f99b2154587d7ab6 (diff) |
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.
Diffstat (limited to 'lib/external_command.rb')
-rw-r--r-- | lib/external_command.rb | 12 |
1 files changed, 8 insertions, 4 deletions
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 |