mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/lib/minitest/unit.rb (parallelize_me!): Removed.
This fixes the line-by-line structure of the test result in verbose mode. [ruby-core:54905] * test/lib/minitest/parallel_each.rb: Removed. * test/minitest/test_minitest_mock.rb: Don't call parallelize_me!. * test/minitest/test_minitest_spec.rb: Ditto. * test/minitest/test_minitest_unit.rb: Ditto. Tests for parallel feature removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46074 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e30e8702a3
commit
36f3ee6dc8
6 changed files with 15 additions and 152 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
||||||
|
Sat May 24 15:49:39 2014 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* test/lib/minitest/unit.rb (parallelize_me!): Removed.
|
||||||
|
This fixes the line-by-line structure of the test result in verbose
|
||||||
|
mode. [ruby-core:54905]
|
||||||
|
|
||||||
|
* test/lib/minitest/parallel_each.rb: Removed.
|
||||||
|
|
||||||
|
* test/minitest/test_minitest_mock.rb: Don't call parallelize_me!.
|
||||||
|
|
||||||
|
* test/minitest/test_minitest_spec.rb: Ditto.
|
||||||
|
|
||||||
|
* test/minitest/test_minitest_unit.rb: Ditto.
|
||||||
|
Tests for parallel feature removed.
|
||||||
|
|
||||||
Sat May 24 15:29:10 2014 Tanaka Akira <akr@fsij.org>
|
Sat May 24 15:29:10 2014 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* test/lib/minitest/hell.rb: Unused file removed.
|
* test/lib/minitest/hell.rb: Unused file removed.
|
||||||
|
|
|
@ -1,75 +0,0 @@
|
||||||
# encoding: utf-8
|
|
||||||
|
|
||||||
##
|
|
||||||
# Provides a parallel #each that lets you enumerate using N threads.
|
|
||||||
# Use environment variable N to customize. Defaults to 2. Enumerable,
|
|
||||||
# so all the goodies come along (tho not all are wrapped yet to
|
|
||||||
# return another ParallelEach instance).
|
|
||||||
|
|
||||||
class ParallelEach
|
|
||||||
require 'thread'
|
|
||||||
include Enumerable
|
|
||||||
|
|
||||||
##
|
|
||||||
# How many Threads to use for this parallel #each.
|
|
||||||
|
|
||||||
N = (ENV['N'] || 2).to_i
|
|
||||||
|
|
||||||
##
|
|
||||||
# Create a new ParallelEach instance over +list+.
|
|
||||||
|
|
||||||
def initialize list
|
|
||||||
@queue = Queue.new # *sigh*... the Queue api sucks sooo much...
|
|
||||||
|
|
||||||
list.each { |i| @queue << i }
|
|
||||||
N.times { @queue << nil }
|
|
||||||
end
|
|
||||||
|
|
||||||
def grep pattern # :nodoc:
|
|
||||||
self.class.new super
|
|
||||||
end
|
|
||||||
|
|
||||||
def select(&block) # :nodoc:
|
|
||||||
self.class.new super
|
|
||||||
end
|
|
||||||
|
|
||||||
alias find_all select # :nodoc:
|
|
||||||
|
|
||||||
##
|
|
||||||
# Starts N threads that yield each element to your block. Joins the
|
|
||||||
# threads at the end.
|
|
||||||
|
|
||||||
def each
|
|
||||||
threads = N.times.map {
|
|
||||||
Thread.new do
|
|
||||||
Thread.current.abort_on_exception = true
|
|
||||||
while job = @queue.pop
|
|
||||||
yield job
|
|
||||||
end
|
|
||||||
end
|
|
||||||
}
|
|
||||||
threads.map(&:join)
|
|
||||||
end
|
|
||||||
|
|
||||||
def count
|
|
||||||
[@queue.size - N, 0].max
|
|
||||||
end
|
|
||||||
|
|
||||||
alias_method :size, :count
|
|
||||||
end
|
|
||||||
|
|
||||||
class MiniTest::Unit
|
|
||||||
alias _old_run_suites _run_suites
|
|
||||||
|
|
||||||
##
|
|
||||||
# Runs all the +suites+ for a given +type+. Runs suites declaring
|
|
||||||
# a test_order of +:parallel+ in parallel, and everything else
|
|
||||||
# serial.
|
|
||||||
|
|
||||||
def _run_suites suites, type
|
|
||||||
parallel, serial = suites.partition { |s| s.test_order == :parallel }
|
|
||||||
|
|
||||||
ParallelEach.new(parallel).map { |suite| _run_suite suite, type } +
|
|
||||||
serial.map { |suite| _run_suite suite, type }
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -902,8 +902,6 @@ module MiniTest
|
||||||
##
|
##
|
||||||
# Runs all the +suites+ for a given +type+.
|
# Runs all the +suites+ for a given +type+.
|
||||||
#
|
#
|
||||||
# NOTE: this method is redefined in parallel_each.rb, which is
|
|
||||||
# loaded if a test-suite calls parallelize_me!.
|
|
||||||
|
|
||||||
def _run_suites suites, type
|
def _run_suites suites, type
|
||||||
suites.map { |suite| _run_suite suite, type }
|
suites.map { |suite| _run_suite suite, type }
|
||||||
|
@ -1346,20 +1344,6 @@ module MiniTest
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
|
||||||
# Call this at the top of your tests when you want to run your
|
|
||||||
# tests in parallel. In doing so, you're admitting that you rule
|
|
||||||
# and your tests are awesome.
|
|
||||||
|
|
||||||
def self.parallelize_me!
|
|
||||||
require "minitest/parallel_each"
|
|
||||||
|
|
||||||
class << self
|
|
||||||
undef_method :test_order if method_defined? :test_order
|
|
||||||
define_method :test_order do :parallel end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.inherited klass # :nodoc:
|
def self.inherited klass # :nodoc:
|
||||||
@@test_suites[klass] = true
|
@@test_suites[klass] = true
|
||||||
super
|
super
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
require 'minitest/autorun'
|
require 'minitest/autorun'
|
||||||
|
|
||||||
class TestMiniTestMock < MiniTest::Unit::TestCase
|
class TestMiniTestMock < MiniTest::Unit::TestCase
|
||||||
parallelize_me!
|
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@mock = MiniTest::Mock.new.expect(:foo, nil)
|
@mock = MiniTest::Mock.new.expect(:foo, nil)
|
||||||
@mock.expect(:meaning_of_life, 42)
|
@mock.expect(:meaning_of_life, 42)
|
||||||
|
@ -273,8 +271,6 @@ end
|
||||||
require "minitest/metametameta"
|
require "minitest/metametameta"
|
||||||
|
|
||||||
class TestMiniTestStub < MiniTest::Unit::TestCase
|
class TestMiniTestStub < MiniTest::Unit::TestCase
|
||||||
parallelize_me!
|
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
MiniTest::Unit::TestCase.reset
|
MiniTest::Unit::TestCase.reset
|
||||||
|
|
|
@ -593,8 +593,6 @@ class TestMetaStatic < MiniTest::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
class TestMeta < MiniTest::Unit::TestCase
|
class TestMeta < MiniTest::Unit::TestCase
|
||||||
parallelize_me!
|
|
||||||
|
|
||||||
def util_structure
|
def util_structure
|
||||||
x = y = z = nil
|
x = y = z = nil
|
||||||
before_list = []
|
before_list = []
|
||||||
|
|
|
@ -8,8 +8,6 @@ class AnError < StandardError; include MyModule; end
|
||||||
class ImmutableString < String; def inspect; super.freeze; end; end
|
class ImmutableString < String; def inspect; super.freeze; end; end
|
||||||
|
|
||||||
class TestMiniTestUnit < MetaMetaMetaTestCase
|
class TestMiniTestUnit < MetaMetaMetaTestCase
|
||||||
parallelize_me!
|
|
||||||
|
|
||||||
pwd = Pathname.new File.expand_path Dir.pwd
|
pwd = Pathname.new File.expand_path Dir.pwd
|
||||||
basedir = Pathname.new(File.expand_path "lib/minitest") + 'mini'
|
basedir = Pathname.new(File.expand_path "lib/minitest") + 'mini'
|
||||||
basedir = basedir.relative_path_from(pwd).to_s
|
basedir = basedir.relative_path_from(pwd).to_s
|
||||||
|
@ -558,56 +556,6 @@ class TestMiniTestRunner < MetaMetaMetaTestCase
|
||||||
@lock.synchronize { @cv.wait_while { @count > 0 } }
|
@lock.synchronize { @cv.wait_while { @count > 0 } }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_parallel_each_size
|
|
||||||
assert_equal 0, ParallelEach.new([]).size
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_run_parallel
|
|
||||||
skip "I don't have ParallelEach debugged yet" if maglev?
|
|
||||||
|
|
||||||
test_count = 2
|
|
||||||
test_latch = Latch.new test_count
|
|
||||||
main_latch = Latch.new
|
|
||||||
|
|
||||||
thread = Thread.new {
|
|
||||||
Thread.current.abort_on_exception = true
|
|
||||||
|
|
||||||
# This latch waits until both test latches have been released. Both
|
|
||||||
# latches can't be released unless done in separate threads because
|
|
||||||
# `main_latch` keeps the test method from finishing.
|
|
||||||
test_latch.await
|
|
||||||
main_latch.release
|
|
||||||
}
|
|
||||||
|
|
||||||
Class.new MiniTest::Unit::TestCase do
|
|
||||||
parallelize_me!
|
|
||||||
|
|
||||||
test_count.times do |i|
|
|
||||||
define_method :"test_wait_on_main_thread_#{i}" do
|
|
||||||
test_latch.release
|
|
||||||
|
|
||||||
# This latch blocks until the "main thread" releases it. The main
|
|
||||||
# thread can't release this latch until both test latches have
|
|
||||||
# been released. This forces the latches to be released in separate
|
|
||||||
# threads.
|
|
||||||
main_latch.await
|
|
||||||
assert true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
expected = clean <<-EOM
|
|
||||||
..
|
|
||||||
|
|
||||||
Finished tests in 0.00
|
|
||||||
|
|
||||||
2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
|
|
||||||
EOM
|
|
||||||
|
|
||||||
assert_report expected
|
|
||||||
assert thread.join
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class TestMiniTestUnitOrder < MetaMetaMetaTestCase
|
class TestMiniTestUnitOrder < MetaMetaMetaTestCase
|
||||||
|
@ -1392,7 +1340,6 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
||||||
|
|
||||||
def test_capture_subprocess_io
|
def test_capture_subprocess_io
|
||||||
@assertion_count = 0
|
@assertion_count = 0
|
||||||
skip "Dunno why but the parallel run of this fails"
|
|
||||||
|
|
||||||
non_verbose do
|
non_verbose do
|
||||||
out, err = capture_subprocess_io do
|
out, err = capture_subprocess_io do
|
||||||
|
@ -1756,8 +1703,6 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
class TestMiniTestGuard < MiniTest::Unit::TestCase
|
class TestMiniTestGuard < MiniTest::Unit::TestCase
|
||||||
parallelize_me!
|
|
||||||
|
|
||||||
def test_mri_eh
|
def test_mri_eh
|
||||||
assert self.class.mri? "ruby blah"
|
assert self.class.mri? "ruby blah"
|
||||||
assert self.mri? "ruby blah"
|
assert self.mri? "ruby blah"
|
||||||
|
|
Loading…
Add table
Reference in a new issue