ruby-changes:45482
From: nobu <ko1@a...>
Date: Tue, 7 Feb 2017 12:55:52 +0900 (JST)
Subject: [ruby-changes:45482] nobu:r57555 (trunk): test/unit: record in parallel
nobu 2017-02-07 12:55:47 +0900 (Tue, 07 Feb 2017) New Revision: 57555 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57555 Log: test/unit: record in parallel * test/lib/test/unit.rb (Test::Unit::Parallel#deal): deal with record. * test/lib/test/unit/parallel.rb (Test::Unit::Worker#record): report test records to the master. Modified files: trunk/test/lib/test/unit/parallel.rb trunk/test/lib/test/unit.rb trunk/test/testunit/test_parallel.rb Index: test/testunit/test_parallel.rb =================================================================== --- test/testunit/test_parallel.rb (revision 57554) +++ test/testunit/test_parallel.rb (revision 57555) @@ -43,6 +43,7 @@ module TestParallel https://github.com/ruby/ruby/blob/trunk/test/testunit/test_parallel.rb#L43 assert_match(/^ready/,@worker_out.gets) @worker_in.puts "run #{TESTS}/ptest_first.rb test" assert_match(/^okay/,@worker_out.gets) + assert_match(/^record/,@worker_out.gets) assert_match(/^p/,@worker_out.gets) assert_match(/^done/,@worker_out.gets) assert_match(/^ready/,@worker_out.gets) @@ -54,8 +55,10 @@ module TestParallel https://github.com/ruby/ruby/blob/trunk/test/testunit/test_parallel.rb#L55 assert_match(/^ready/,@worker_out.gets) @worker_in.puts "run #{TESTS}/ptest_second.rb test" assert_match(/^okay/,@worker_out.gets) + assert_match(/^record/,@worker_out.gets) assert_match(/^p/,@worker_out.gets) assert_match(/^done/,@worker_out.gets) + assert_match(/^record/,@worker_out.gets) assert_match(/^p/,@worker_out.gets) assert_match(/^done/,@worker_out.gets) assert_match(/^ready/,@worker_out.gets) @@ -67,13 +70,16 @@ module TestParallel https://github.com/ruby/ruby/blob/trunk/test/testunit/test_parallel.rb#L70 assert_match(/^ready/,@worker_out.gets) @worker_in.puts "run #{TESTS}/ptest_first.rb test" assert_match(/^okay/,@worker_out.gets) + assert_match(/^record/,@worker_out.gets) assert_match(/^p/,@worker_out.gets) assert_match(/^done/,@worker_out.gets) assert_match(/^ready/,@worker_out.gets) @worker_in.puts "run #{TESTS}/ptest_second.rb test" assert_match(/^okay/,@worker_out.gets) + assert_match(/^record/,@worker_out.gets) assert_match(/^p/,@worker_out.gets) assert_match(/^done/,@worker_out.gets) + assert_match(/^record/,@worker_out.gets) assert_match(/^p/,@worker_out.gets) assert_match(/^done/,@worker_out.gets) assert_match(/^ready/,@worker_out.gets) @@ -93,11 +99,9 @@ module TestParallel https://github.com/ruby/ruby/blob/trunk/test/testunit/test_parallel.rb#L99 def test_done Timeout.timeout(10) do @worker_in.puts "run #{TESTS}/ptest_forth.rb test" - 7.times { @worker_out.gets } - buf = @worker_out.gets - assert_match(/^done (.+?)$/, buf) - - /^done (.+?)$/ =~ buf + while buf = @worker_out.gets + break if /^done (.+?)$/ =~ buf + end result = Marshal.load($1.chomp.unpack("m")[0]) Index: test/lib/test/unit.rb =================================================================== --- test/lib/test/unit.rb (revision 57554) +++ test/lib/test/unit.rb (revision 57555) @@ -372,6 +372,11 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit.rb#L372 end end + FakeClass = Struct.new(:name) + def fake_class(name) + (@fake_classes ||= {})[name] ||= FakeClass.new(name) + end + def deal(io, type, result, rep, shutting_down = false) worker = @workers_hash[io] cmd = worker.read @@ -409,6 +414,14 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit.rb#L414 $:.push(*r[4]).uniq! jobs_status(worker) if @options[:job_status] == :replace return true + when /^record (.+?)$/ + begin + r = Marshal.load($1.unpack("m")[0]) + rescue => e + print "unknown record: #{e.message} #{$1.unpack("m")[0].dump}" + return true + end + record(fake_class(r[0]), *r[1..-1]) when /^p (.+?)$/ del_jobs_status print $1.unpack("m")[0] Index: test/lib/test/unit/parallel.rb =================================================================== --- test/lib/test/unit/parallel.rb (revision 57554) +++ test/lib/test/unit/parallel.rb (revision 57555) @@ -165,6 +165,24 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit/parallel.rb#L165 @partial_report << [klass.name, meth, e.is_a?(MiniTest::Assertion) ? e : ProxyError.new(e)] super end + + def record(suite, method, assertions, time, error) # :nodoc: + case error + when nil + when MiniTest::Assertion, MiniTest::Skip + case error.cause + when nil, MiniTest::Assertion, MiniTest::Skip + else + bt = error.backtrace + error = error.class.new(error.message) + error.set_backtrace(bt) + end + else + error = ProxyError.new(error) + end + _report "record", Marshal.dump([suite.name, method, assertions, time, error]) + super + end end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/