2011-02-23 09:08:25 -05:00
|
|
|
require 'test/unit'
|
|
|
|
require 'timeout'
|
|
|
|
|
|
|
|
module TestParallel
|
2014-05-17 02:26:51 -04:00
|
|
|
PARALLEL_RB = "#{File.dirname(__FILE__)}/../lib/test/unit/parallel.rb"
|
2011-02-23 09:08:25 -05:00
|
|
|
TESTS = "#{File.dirname(__FILE__)}/tests_for_parallel"
|
|
|
|
|
|
|
|
class TestParallelWorker < Test::Unit::TestCase
|
|
|
|
def setup
|
|
|
|
i, @worker_in = IO.pipe
|
|
|
|
@worker_out, o = IO.pipe
|
2011-02-23 23:47:48 -05:00
|
|
|
@worker_pid = spawn(*@options[:ruby], PARALLEL_RB,
|
2011-08-02 07:18:58 -04:00
|
|
|
"--ruby", @options[:ruby].join(" "),
|
2011-02-23 09:08:25 -05:00
|
|
|
"-j", "t1", "-v", out: o, in: i)
|
|
|
|
[i,o].each(&:close)
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
2011-02-27 21:58:35 -05:00
|
|
|
if @worker_pid && @worker_in
|
|
|
|
begin
|
2011-07-07 04:56:12 -04:00
|
|
|
begin
|
|
|
|
@worker_in.puts "quit"
|
|
|
|
rescue IOError, Errno::EPIPE
|
|
|
|
end
|
2015-07-13 06:07:01 -04:00
|
|
|
Timeout.timeout(2) do
|
2011-02-27 21:58:35 -05:00
|
|
|
Process.waitpid(@worker_pid)
|
|
|
|
end
|
2011-07-07 04:56:12 -04:00
|
|
|
rescue Timeout::Error
|
2011-06-12 14:20:25 -04:00
|
|
|
begin
|
|
|
|
Process.kill(:KILL, @worker_pid)
|
|
|
|
rescue Errno::ESRCH
|
|
|
|
end
|
2011-02-23 09:08:25 -05:00
|
|
|
end
|
|
|
|
end
|
2014-05-30 10:17:46 -04:00
|
|
|
ensure
|
|
|
|
@worker_in.close
|
|
|
|
@worker_out.close
|
2011-02-23 09:08:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_run
|
2015-07-13 06:07:01 -04:00
|
|
|
Timeout.timeout(10) do
|
2011-02-23 09:08:25 -05:00
|
|
|
assert_match(/^ready/,@worker_out.gets)
|
2011-07-10 08:19:16 -04:00
|
|
|
@worker_in.puts "run #{TESTS}/ptest_first.rb test"
|
2011-02-23 09:08:25 -05:00
|
|
|
assert_match(/^okay/,@worker_out.gets)
|
|
|
|
assert_match(/^p/,@worker_out.gets)
|
|
|
|
assert_match(/^done/,@worker_out.gets)
|
|
|
|
assert_match(/^ready/,@worker_out.gets)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_run_multiple_testcase_in_one_file
|
2015-07-13 06:07:01 -04:00
|
|
|
Timeout.timeout(10) do
|
2011-02-23 09:08:25 -05:00
|
|
|
assert_match(/^ready/,@worker_out.gets)
|
2011-07-10 08:19:16 -04:00
|
|
|
@worker_in.puts "run #{TESTS}/ptest_second.rb test"
|
2011-02-23 09:08:25 -05:00
|
|
|
assert_match(/^okay/,@worker_out.gets)
|
|
|
|
assert_match(/^p/,@worker_out.gets)
|
|
|
|
assert_match(/^done/,@worker_out.gets)
|
|
|
|
assert_match(/^p/,@worker_out.gets)
|
|
|
|
assert_match(/^done/,@worker_out.gets)
|
|
|
|
assert_match(/^ready/,@worker_out.gets)
|
|
|
|
end
|
|
|
|
end
|
2011-02-26 09:51:35 -05:00
|
|
|
|
2011-02-23 09:08:25 -05:00
|
|
|
def test_accept_run_command_multiple_times
|
2015-07-13 06:07:01 -04:00
|
|
|
Timeout.timeout(10) do
|
2011-02-23 09:08:25 -05:00
|
|
|
assert_match(/^ready/,@worker_out.gets)
|
2011-07-10 08:19:16 -04:00
|
|
|
@worker_in.puts "run #{TESTS}/ptest_first.rb test"
|
2011-02-23 09:08:25 -05:00
|
|
|
assert_match(/^okay/,@worker_out.gets)
|
|
|
|
assert_match(/^p/,@worker_out.gets)
|
|
|
|
assert_match(/^done/,@worker_out.gets)
|
|
|
|
assert_match(/^ready/,@worker_out.gets)
|
2011-07-10 08:19:16 -04:00
|
|
|
@worker_in.puts "run #{TESTS}/ptest_second.rb test"
|
2011-02-23 09:08:25 -05:00
|
|
|
assert_match(/^okay/,@worker_out.gets)
|
|
|
|
assert_match(/^p/,@worker_out.gets)
|
|
|
|
assert_match(/^done/,@worker_out.gets)
|
|
|
|
assert_match(/^p/,@worker_out.gets)
|
|
|
|
assert_match(/^done/,@worker_out.gets)
|
|
|
|
assert_match(/^ready/,@worker_out.gets)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_p
|
2015-07-13 06:07:01 -04:00
|
|
|
Timeout.timeout(10) do
|
2011-07-10 08:19:16 -04:00
|
|
|
@worker_in.puts "run #{TESTS}/ptest_first.rb test"
|
2011-02-23 09:08:25 -05:00
|
|
|
while buf = @worker_out.gets
|
|
|
|
break if /^p (.+?)$/ =~ buf
|
|
|
|
end
|
2011-07-10 08:19:16 -04:00
|
|
|
assert_match(/TestA#test_nothing_test = \d+\.\d+ s = \.\n/, $1.chomp.unpack("m")[0])
|
2011-02-23 09:08:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_done
|
2015-07-13 06:07:01 -04:00
|
|
|
Timeout.timeout(10) do
|
2011-07-10 08:19:16 -04:00
|
|
|
@worker_in.puts "run #{TESTS}/ptest_forth.rb test"
|
2014-05-15 08:31:26 -04:00
|
|
|
7.times { @worker_out.gets }
|
2011-07-10 08:19:16 -04:00
|
|
|
buf = @worker_out.gets
|
|
|
|
assert_match(/^done (.+?)$/, buf)
|
|
|
|
|
|
|
|
/^done (.+?)$/ =~ buf
|
2011-02-23 09:08:25 -05:00
|
|
|
|
|
|
|
result = Marshal.load($1.chomp.unpack("m")[0])
|
|
|
|
|
2014-05-15 08:31:26 -04:00
|
|
|
assert_equal(5, result[0])
|
2012-08-20 20:07:32 -04:00
|
|
|
assert_equal(2, result[1])
|
2011-02-23 09:08:25 -05:00
|
|
|
assert_kind_of(Array,result[2])
|
|
|
|
assert_kind_of(Array,result[3])
|
|
|
|
assert_kind_of(Array,result[4])
|
2012-06-15 18:46:08 -04:00
|
|
|
assert_kind_of(Array,result[2][1])
|
|
|
|
assert_kind_of(MiniTest::Assertion,result[2][0][2])
|
|
|
|
assert_kind_of(MiniTest::Skip,result[2][1][2])
|
2014-05-15 08:31:26 -04:00
|
|
|
assert_kind_of(MiniTest::Skip,result[2][2][2])
|
|
|
|
assert_kind_of(Exception, result[2][3][2])
|
2011-02-23 09:08:25 -05:00
|
|
|
assert_equal(result[5], "TestE")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_quit
|
2015-07-13 06:07:01 -04:00
|
|
|
Timeout.timeout(10) do
|
2011-02-23 09:08:25 -05:00
|
|
|
@worker_in.puts "quit"
|
|
|
|
assert_match(/^bye$/m,@worker_out.read)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestParallel < Test::Unit::TestCase
|
|
|
|
def spawn_runner(*opt_args)
|
|
|
|
@test_out, o = IO.pipe
|
2011-02-23 23:47:48 -05:00
|
|
|
@test_pid = spawn(*@options[:ruby], TESTS+"/runner.rb",
|
2011-08-02 07:18:58 -04:00
|
|
|
"--ruby", @options[:ruby].join(" "),
|
2011-06-16 07:24:23 -04:00
|
|
|
"-j","t1",*opt_args, out: o, err: o)
|
2011-02-23 09:08:25 -05:00
|
|
|
o.close
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
begin
|
|
|
|
if @test_pid
|
2015-07-13 06:07:01 -04:00
|
|
|
Timeout.timeout(2) do
|
2011-02-23 09:08:25 -05:00
|
|
|
Process.waitpid(@test_pid)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
rescue Timeout::Error
|
|
|
|
Process.kill(:KILL, @test_pid) if @test_pid
|
|
|
|
ensure
|
|
|
|
@test_out.close if @test_out
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-15 19:06:00 -04:00
|
|
|
def test_ignore_jzero
|
|
|
|
@test_out, o = IO.pipe
|
|
|
|
@test_pid = spawn(*@options[:ruby], TESTS+"/runner.rb",
|
2011-08-02 07:18:58 -04:00
|
|
|
"--ruby", @options[:ruby].join(" "),
|
2011-06-15 19:06:00 -04:00
|
|
|
"-j","0", out: File::NULL, err: o)
|
|
|
|
o.close
|
2015-07-13 06:07:01 -04:00
|
|
|
Timeout.timeout(10) {
|
2011-06-15 19:06:00 -04:00
|
|
|
assert_match(/Error: parameter of -j option should be greater than 0/,@test_out.read)
|
|
|
|
}
|
|
|
|
end
|
2011-02-26 09:51:35 -05:00
|
|
|
|
2011-02-23 09:08:25 -05:00
|
|
|
def test_should_run_all_without_any_leaks
|
|
|
|
spawn_runner
|
2015-07-13 06:07:01 -04:00
|
|
|
buf = Timeout.timeout(10) {@test_out.read}
|
2014-05-15 08:31:26 -04:00
|
|
|
assert_match(/^[SFE\.]{9}$/,buf)
|
2011-02-23 09:08:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_should_retry_failed_on_workers
|
|
|
|
spawn_runner
|
2015-07-13 06:07:01 -04:00
|
|
|
buf = Timeout.timeout(10) {@test_out.read}
|
2011-02-23 09:08:25 -05:00
|
|
|
assert_match(/^Retrying\.+$/,buf)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_no_retry_option
|
|
|
|
spawn_runner "--no-retry"
|
2015-07-13 06:07:01 -04:00
|
|
|
buf = Timeout.timeout(10) {@test_out.read}
|
2011-02-23 09:08:25 -05:00
|
|
|
refute_match(/^Retrying\.+$/,buf)
|
2013-05-02 02:07:17 -04:00
|
|
|
assert_match(/^ +\d+\) Failure:\nTestD#test_fail_at_worker/,buf)
|
2011-02-23 09:08:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_jobs_status
|
|
|
|
spawn_runner "--jobs-status"
|
2015-07-13 06:07:01 -04:00
|
|
|
buf = Timeout.timeout(10) {@test_out.read}
|
2011-07-10 08:19:16 -04:00
|
|
|
assert_match(/\d+=ptest_(first|second|third|forth) */,buf)
|
2011-02-23 09:08:25 -05:00
|
|
|
end
|
|
|
|
|
2011-12-25 09:17:28 -05:00
|
|
|
def test_separate
|
|
|
|
# this test depends to --jobs-status
|
|
|
|
spawn_runner "--jobs-status", "--separate"
|
2015-07-13 06:07:01 -04:00
|
|
|
buf = Timeout.timeout(10) {@test_out.read}
|
2011-12-25 09:17:28 -05:00
|
|
|
assert(buf.scan(/(\d+?)[:=]/).flatten.uniq.size > 1)
|
|
|
|
end
|
2011-02-23 09:08:25 -05:00
|
|
|
end
|
|
|
|
end
|