[前][次][番号順一覧][スレッド一覧]

ruby-changes:19663

From: sorah <ko1@a...>
Date: Mon, 23 May 2011 09:11:02 +0900 (JST)
Subject: [ruby-changes:19663] sorah:r31708 (trunk): * lib/test/unit/parallel.rb: Never Ignore SIGINT. When received

sorah	2011-05-23 09:10:49 +0900 (Mon, 23 May 2011)

  New Revision: 31708

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31708

  Log:
    * lib/test/unit/parallel.rb: Never Ignore SIGINT. When received
    Interrupt, immediately puts result and exit. [ruby-dev:43571]
    
    * lib/test/unit.rb: When received Interrupt, wait results from workers
    and correct them. [ruby-dev:43571]

  Modified files:
    trunk/ChangeLog
    trunk/lib/test/unit/parallel.rb
    trunk/lib/test/unit.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 31707)
+++ ChangeLog	(revision 31708)
@@ -1,3 +1,11 @@
+Mon May 23 09:03:52 2011  Shota Fukumori  <sorah@t...>
+
+	* lib/test/unit/parallel.rb: Never Ignore SIGINT. When received
+	Interrupt, immediately puts result and exit. [ruby-dev:43571]
+
+	* lib/test/unit.rb: When received Interrupt, wait results from workers
+	and correct them. [ruby-dev:43571]
+
 Mon May 23 09:08:07 2011  Eric Hodel  <drbrain@s...>
 
 	* lib/mathn.rb:  Improve documentation.  Patch by Sandor Szucs.
Index: lib/test/unit/parallel.rb
===================================================================
--- lib/test/unit/parallel.rb	(revision 31707)
+++ lib/test/unit/parallel.rb	(revision 31708)
@@ -42,7 +42,12 @@
 
         e, f, s = @errors, @failures, @skips
 
-        result = orig_run_suite(suite, type)
+        begin
+          result = orig_run_suite(suite, type)
+        rescue Interrupt
+          @need_exit = true
+          result = [nil,nil]
+        end
 
         MiniTest::Unit.output = orig_stdout
 
@@ -73,8 +78,8 @@
         process_args args
         @@stop_auto_run = true
         @opts = @options.dup
+        @need_exit = false
 
-        Signal.trap(:INT,"IGNORE")
         @old_loadpath = []
         begin
           @stdout = increment_io(STDOUT)
@@ -101,7 +106,14 @@
               end
               _run_suites MiniTest::Unit::TestCase.test_suites-suites, $2.to_sym
 
-              @stdout.puts "ready"
+              if @need_exit
+                begin
+                  @stdout.puts "bye"
+                rescue Errno::EPIPE; end
+                exit
+              else
+                @stdout.puts "ready"
+              end
             when /^quit$/
               begin
                 @stdout.puts "bye"
Index: lib/test/unit.rb
===================================================================
--- lib/test/unit.rb	(revision 31707)
+++ lib/test/unit.rb	(revision 31708)
@@ -445,7 +445,7 @@
                 jobs_status
               when /^done (.+?)$/
                 r = Marshal.load($1.unpack("m")[0])
-                result << r[0..1]
+                result << r[0..1] unless r[0..1] == [nil,nil]
                 rep    << {file: worker.real_file,
                            report: r[2], result: r[3], testcase: r[5]}
                 $:.push(*r[4]).uniq!
@@ -474,6 +474,24 @@
           shutting_down = true
 
           watchdog.kill if watchdog
+          if @interrupt
+            @ios.select!{|x| @workers_hash[x].status == :running }
+            while !@ios.empty? && (__io = IO.select(@ios,[],[],10))
+                _io = __io[0]
+                _io.each do |io|
+                  worker = @workers_hash[io]
+                  case worker.read
+                  when /^done (.+?)$/
+                    r = Marshal.load($1.unpack("m")[0])
+                    result << r[0..1] unless r[0..1] == [nil,nil]
+                    rep    << {file: worker.real_file,
+                               report: r[2], result: r[3], testcase: r[5]}
+                    $:.push(*r[4]).uniq!
+                    @ios.delete(io)
+                  end
+                end
+            end
+          end
           @workers.each do |worker|
             begin
               timeout(1) do
@@ -500,9 +518,9 @@
             rep.each do |r|
               report.push(*r[:report])
             end
-            @errors += rep.map{|x| x[:result][0] }.inject(:+)
+            @errors   += rep.map{|x| x[:result][0] }.inject(:+)
             @failures += rep.map{|x| x[:result][1] }.inject(:+)
-            @skips += rep.map{|x| x[:result][2] }.inject(:+)
+            @skips    += rep.map{|x| x[:result][2] }.inject(:+)
           else
             puts ""
             puts "Retrying..."

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]