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