diff options
author | sorah <sorah@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-12-25 13:47:21 +0000 |
---|---|---|
committer | sorah <sorah@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-12-25 13:47:21 +0000 |
commit | 60da7a36f52bc1d558aa1ed44090259c37ac7bd4 (patch) | |
tree | becf7c812fb008e8be748d289a151f2a672a9376 /lib | |
parent | f8a4e2331b293178a8d137846875f5ce9119be82 (diff) | |
download | ruby-60da7a36f52bc1d558aa1ed44090259c37ac7bd4.tar.gz |
* lib/test/unit.rb (_run_parallel):
New option "--separate" for test/unit; when running tests with this
option, a job process will be restarted after one testcase has done.
This means all testcases will run with separated process.
* lib/test/unit/parallel.rb: Fix for above. Now parallel.rb puts
"ready!" for first ready, "ready" for afters.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34121 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/test/unit.rb | 41 | ||||
-rw-r--r-- | lib/test/unit/parallel.rb | 2 |
2 files changed, 35 insertions, 8 deletions
diff --git a/lib/test/unit.rb b/lib/test/unit.rb index 651ba0a939..6068e295fb 100644 --- a/lib/test/unit.rb +++ b/lib/test/unit.rb @@ -96,6 +96,11 @@ module Test end end + opts.on '--separate', "Restart job process after one testcase has done" do + options[:parallel] ||= 1 + options[:separate] = true + end + opts.on '--no-retry', "Don't retry running testcase when --jobs specified" do options[:no_retry] = true end @@ -243,6 +248,8 @@ module Test new(io, io.pid, :waiting) end + attr_reader :quit_called + def initialize(io, pid, status) @io = io @pid = pid @@ -251,6 +258,7 @@ module Test @real_file = nil @loadpath = [] @hooks = {} + @quit_called = false end def puts(*args) @@ -289,6 +297,12 @@ module Test self end + def quit + return if @io.closed? + @quit_called = true + @io.puts "quit" + end + def died(*additional) @status = :quit @io.close @@ -401,14 +415,15 @@ module Test rep = [] # FIXME: more good naming # Array of workers. - @workers = @options[:parallel].times.map { + launch_worker = Proc.new { worker = Worker.launch(@options[:ruby],@args) worker.hook(:dead) do |w,info| after_worker_quit w - after_worker_down w, *info unless info.empty? + after_worker_down w, *info if !info.empty? && !worker.quit_called end worker } + @workers = @options[:parallel].times.map(&launch_worker) # Thread: watchdog watchdog = Thread.new do @@ -417,7 +432,7 @@ module Test pid, stat = stat w = (@workers + @dead_workers).find{|x| pid == x.pid }.dup next unless w - unless w.status == :quit + if w.status != :quit && !w.quit_called? # Worker down w.died(nil, !stat.signaled? && stat.exitstatus) end @@ -435,11 +450,23 @@ module Test when /^okay$/ worker.status = :running jobs_status - when /^ready$/ + when /^ready(!?)$/ + bang = $1 worker.status = :ready if @tasks.empty? break unless @workers.find{|x| x.status == :running } else + if @options[:separate] && bang.empty? + @workers_hash.delete worker.io + @workers.delete worker + @ios.delete worker.io + new_worker = launch_worker.call() + worker.quit + @workers << new_worker + @ios << new_worker.io + @workers_hash[new_worker.io] = new_worker + worker = new_worker + end worker.run(@tasks.shift, type) end @@ -459,7 +486,7 @@ module Test when /^bye (.+?)$/ after_worker_down worker, Marshal.load($1.unpack("m")[0]) when /^bye$/ - if shutting_down + if shutting_down || worker.quit_called after_worker_quit worker else after_worker_down worker @@ -496,7 +523,7 @@ module Test @workers.each do |worker| begin timeout(1) do - worker.puts "quit" + worker.quit end rescue Errno::EPIPE rescue Timeout::Error @@ -529,7 +556,7 @@ module Test rep.each do |r| if r[:testcase] && r[:file] && !r[:report].empty? require r[:file] - _run_suite(eval(r[:testcase]),type) + _run_suite(eval("::"+r[:testcase]),type) else report.push(*r[:report]) @errors += r[:result][0] diff --git a/lib/test/unit/parallel.rb b/lib/test/unit/parallel.rb index 7a7c73d4f2..3ce95b9bd8 100644 --- a/lib/test/unit/parallel.rb +++ b/lib/test/unit/parallel.rb @@ -91,7 +91,7 @@ module Test @stdout = increment_io(STDOUT) @stdin = increment_io(STDIN) @stdout.sync = true - @stdout.puts "ready" + @stdout.puts "ready!" while buf = @stdin.gets case buf.chomp when /^loadpath (.+?)$/ |