bootstraptest/test_{fork,io,thread}.rb: reduce sleep times

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46379 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-06-07 19:57:46 +00:00
parent 7d8fc3696e
commit 85521e60ee
3 changed files with 57 additions and 39 deletions

View File

@ -22,26 +22,32 @@ assert_finish 10, %q{
}, '[ruby-core:22158]' }, '[ruby-core:22158]'
assert_normal_exit(<<'End', '[ruby-dev:37934]') assert_normal_exit(<<'End', '[ruby-dev:37934]')
Thread.new { sleep 1; Thread.kill Thread.main } main = Thread.current
Thread.new { sleep 0.01 until main.stop?; Thread.kill main }
Process.setrlimit(:NPROC, 1) Process.setrlimit(:NPROC, 1)
fork {} fork {}
End End
assert_equal 'ok', %q{ assert_equal 'ok', %q{
begin begin
r, w = IO.pipe
if pid1 = fork if pid1 = fork
sleep 1 w.close
r.read(1)
Process.kill("USR1", pid1) Process.kill("USR1", pid1)
_, s = Process.wait2(pid1) _, s = Process.wait2(pid1)
s.success? ? :ok : :ng s.success? ? :ok : :ng
else else
r.close
if pid2 = fork if pid2 = fork
trap("USR1") { Time.now.to_s } trap("USR1") { Time.now.to_s; Process.kill("USR2", pid2) }
w.close
Process.wait2(pid2) Process.wait2(pid2)
else else
sleep 2 w.close
sleep 0.2
end end
exit 0 exit true
end end
rescue NotImplementedError rescue NotImplementedError
:ok :ok
@ -50,17 +56,16 @@ assert_equal 'ok', %q{
assert_equal '[1, 2]', %q{ assert_equal '[1, 2]', %q{
a = [] a = []
trap(:INT) { a.push(1) } main = Thread.current
trap(:TERM) { a.push(2) } trap(:INT) { a.push(1).size == 2 and main.wakeup }
trap(:TERM) { a.push(2).size == 2 and main.wakeup }
pid = $$ pid = $$
begin begin
fork do pid = fork do
sleep 0.5
Process.kill(:INT, pid) Process.kill(:INT, pid)
Process.kill(:TERM, pid) Process.kill(:TERM, pid)
end end
Process.wait(pid)
sleep 1
a.sort a.sort
rescue NotImplementedError rescue NotImplementedError
[1, 2] [1, 2]

View File

@ -2,9 +2,8 @@ assert_finish 5, %q{
r, w = IO.pipe r, w = IO.pipe
t1 = Thread.new { r.sysread(1) } t1 = Thread.new { r.sysread(1) }
t2 = Thread.new { r.sysread(1) } t2 = Thread.new { r.sysread(1) }
sleep 0.1 sleep 0.01 until t1.stop? and t2.stop?
w.write "a" w.write "a"
sleep 0.1
w.write "a" w.write "a"
}, '[ruby-dev:31866]' }, '[ruby-dev:31866]'
@ -34,9 +33,9 @@ assert_finish 10, %q{
assert_finish 1, %q{ assert_finish 1, %q{
r, w = IO.pipe r, w = IO.pipe
Thread.new { Thread.new {
w << "ab" w << "ab"
sleep 0.1 sleep 0.01
w << "ab" w << "ab"
} }
r.gets("abab") r.gets("abab")
} }
@ -91,7 +90,8 @@ assert_normal_exit %q{
megacontent = "abc" * 12345678 megacontent = "abc" * 12345678
#File.open("megasrc", "w") {|f| f << megacontent } #File.open("megasrc", "w") {|f| f << megacontent }
Thread.new { sleep rand*0.2; Process.kill(:INT, $$) } t0 = Thread.main
Thread.new { sleep 0.001 until t0.stop?; Process.kill(:INT, $$) }
r1, w1 = IO.pipe r1, w1 = IO.pipe
r2, w2 = IO.pipe r2, w2 = IO.pipe

View File

@ -241,16 +241,16 @@ assert_equal 'ok', %{
} }
assert_finish 3, %{ assert_finish 3, %{
th = Thread.new {sleep 2} th = Thread.new {sleep 0.2}
th.join(1) th.join(0.1)
th.join th.join
} }
assert_finish 3, %{ assert_finish 3, %{
require 'timeout' require 'timeout'
th = Thread.new {sleep 2} th = Thread.new {sleep 0.2}
begin begin
Timeout.timeout(1) {th.join} Timeout.timeout(0.1) {th.join}
rescue Timeout::Error rescue Timeout::Error
end end
th.join th.join
@ -276,7 +276,7 @@ assert_normal_exit %q{
assert_equal 'ok', %q{ assert_equal 'ok', %q{
def m def m
t = Thread.new { while true; // =~ "" end } t = Thread.new { while true; // =~ "" end }
sleep 0.1 sleep 0.01
10.times { 10.times {
if /((ab)*(ab)*)*(b)/ =~ "ab"*7 if /((ab)*(ab)*)*(b)/ =~ "ab"*7
return :ng if !$4 return :ng if !$4
@ -340,8 +340,9 @@ assert_equal 'ok', %q{
assert_equal 'ok', %q{ assert_equal 'ok', %q{
begin begin
m1, m2 = Mutex.new, Mutex.new m1, m2 = Mutex.new, Mutex.new
Thread.new { m1.lock; sleep 1; m2.lock } f1 = f2 = false
m2.lock; sleep 1; m1.lock Thread.new { m1.lock; f2 = true; sleep 0.001 until f1; m2.lock }
m2.lock; f1 = true; sleep 0.001 until f2; m1.lock
:ng :ng
rescue Exception rescue Exception
:ok :ok
@ -350,7 +351,7 @@ assert_equal 'ok', %q{
assert_equal 'ok', %q{ assert_equal 'ok', %q{
m = Mutex.new m = Mutex.new
Thread.new { m.lock }; sleep 1; m.lock Thread.new { m.lock }; sleep 0.1; m.lock
:ok :ok
} }
@ -368,15 +369,15 @@ assert_equal 'ok', %q{
assert_equal 'ok', %q{ assert_equal 'ok', %q{
m = Mutex.new m = Mutex.new
Thread.new { m.lock; sleep 2 } Thread.new { m.lock; sleep 0.2 }
sleep 1; m.lock sleep 0.1; m.lock
:ok :ok
} }
assert_equal 'ok', %q{ assert_equal 'ok', %q{
m = Mutex.new m = Mutex.new
Thread.new { m.lock; sleep 2; m.unlock } Thread.new { m.lock; sleep 0.2; m.unlock }
sleep 1; m.lock sleep 0.1; m.lock
:ok :ok
} }
@ -398,19 +399,20 @@ assert_equal 'ok', %q{
assert_equal 'ok', %{ assert_equal 'ok', %{
open("zzz.rb", "w") do |f| open("zzz.rb", "w") do |f|
f.puts <<-END f.puts <<-'end;' # do
begin begin
m = Mutex.new m = Mutex.new
Thread.new { m.lock; sleep 1 }
sleep 0.3
parent = Thread.current parent = Thread.current
th1 = Thread.new { m.lock; sleep }
sleep 0.01 until th1.stop?
Thread.new do Thread.new do
sleep 0.3 sleep 0.01 until parent.stop?
begin begin
fork { GC.start } fork { GC.start }
rescue Exception rescue Exception
parent.raise $! parent.raise $!
end end
th1.run
end end
m.lock m.lock
pid, status = Process.wait2 pid, status = Process.wait2
@ -418,7 +420,7 @@ assert_equal 'ok', %{
rescue NotImplementedError rescue NotImplementedError
$result = :ok $result = :ok
end end
END end;
end end
require "./zzz.rb" require "./zzz.rb"
$result $result
@ -448,17 +450,28 @@ assert_finish 3, %q{
assert_equal 'ok', %q{ assert_equal 'ok', %q{
begin begin
Process.waitpid2(fork {sleep 1})[1].success? ? 'ok' : 'ng' Process.waitpid2(fork {})[1].success? ? 'ok' : 'ng'
rescue NotImplementedError rescue NotImplementedError
'ok' 'ok'
end end
} }
assert_equal 'foo', %q{ assert_equal 'foo', %q{
f = proc {|s| /#{ sleep 1; s }/o } i = 0
[ Thread.new { f.call("foo"); nil }, th2 = nil
Thread.new { sleep 0.5; f.call("bar"); nil }, Thread.start {sleep 1; exit!}
].each {|t| t.join } f = proc {|s, c| /#{c.call; s}/o }
th2 = Thread.new {
sleep 0.01 until i == 1
i = 2
f.call("bar", proc {sleep 2});
nil
}
th1 = Thread.new {
f.call("foo", proc {i = 1; sleep 0.01 until i == 2; sleep 0.01})
nil
}
[th1, th2].each {|t| t.join }
GC.start GC.start
f.call.source f.call.source
} }