ruby-changes:22072
From: sorah <ko1@a...>
Date: Sun, 25 Dec 2011 22:47:33 +0900 (JST)
Subject: [ruby-changes:22072] sorah:r34121 (trunk): * lib/test/unit.rb (_run_parallel):
sorah 2011-12-25 22:47:21 +0900 (Sun, 25 Dec 2011) New Revision: 34121 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34121 Log: * 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. Modified files: trunk/ChangeLog trunk/lib/test/unit/parallel.rb trunk/lib/test/unit.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 34120) +++ ChangeLog (revision 34121) @@ -1,3 +1,13 @@ +Sun Dec 25 22:39:49 2011 Shota Fukumori <sorah@t...> + + * 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. + Sun Dec 25 00:02:15 2011 Luis Lavena <luislavena@g...> * configure.in: change --with-ntver to --with-winnt-ver to be more Index: lib/test/unit/parallel.rb =================================================================== --- lib/test/unit/parallel.rb (revision 34120) +++ lib/test/unit/parallel.rb (revision 34121) @@ -91,7 +91,7 @@ @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 (.+?)$/ Index: lib/test/unit.rb =================================================================== --- lib/test/unit.rb (revision 34120) +++ lib/test/unit.rb (revision 34121) @@ -96,6 +96,11 @@ 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 @@ new(io, io.pid, :waiting) end + attr_reader :quit_called + def initialize(io, pid, status) @io = io @pid = pid @@ -251,6 +258,7 @@ @real_file = nil @loadpath = [] @hooks = {} + @quit_called = false end def puts(*args) @@ -289,6 +297,12 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ @workers.each do |worker| begin timeout(1) do - worker.puts "quit" + worker.quit end rescue Errno::EPIPE rescue Timeout::Error @@ -529,7 +556,7 @@ 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] -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/