From f09830603644e2c09a696b5c468b810b099f1896 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 14 Jul 2012 07:16:19 +0000 Subject: [PATCH] test/unit.rb: extract start_watchdog * lib/test/unit.rb (Test::Unit::Runner#start_watchdog): extract. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 +++- lib/test/unit.rb | 31 +++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 44cc6430b4..2685ff19b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ -Sat Jul 14 16:16:12 2012 Nobuyoshi Nakada +Sat Jul 14 16:16:17 2012 Nobuyoshi Nakada + + * lib/test/unit.rb (Test::Unit::Runner#start_watchdog): extract. * lib/test/unit.rb (Test::Unit::Runner#_run_parallel): move initializations with nothing to release outside begin/ensure. diff --git a/lib/test/unit.rb b/lib/test/unit.rb index 6076eb8592..22e092a565 100644 --- a/lib/test/unit.rb +++ b/lib/test/unit.rb @@ -452,6 +452,22 @@ module Test @ios = @workers.map(&:io) end + def start_watchdog + Thread.new do + while stat = Process.wait2 + break if @interrupt # Break when interrupt + pid, stat = stat + w = (@workers + @dead_workers).find{|x| pid == x.pid } + next unless w + w = w.dup + if w.status != :quit && !w.quit_called? + # Worker down + w.died(nil, !stat.signaled? && stat.exitstatus) + end + end + end + end + def _run_parallel suites, type, result if @options[:parallel] < 1 warn "Error: parameter of -j option should be greater than 0." @@ -487,20 +503,7 @@ module Test @workers = @options[:parallel].times.map(&launch_worker) # Thread: watchdog - watchdog = Thread.new do - while stat = Process.wait2 - break if @interrupt # Break when interrupt - pid, stat = stat - w = (@workers + @dead_workers).find{|x| pid == x.pid } - next unless w - w = w.dup - if w.status != :quit && !w.quit_called? - # Worker down - w.died(nil, !stat.signaled? && stat.exitstatus) - end - end - end - + watchdog = start_watchdog @workers_hash = Hash[@workers.map {|w| [w.io,w] }] # out-IO => worker @ios = @workers.map{|w| w.io } # Array of worker IOs