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
Родитель 7d8fc3696e
Коммит 85521e60ee
3 изменённых файлов: 57 добавлений и 39 удалений

Просмотреть файл

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

Просмотреть файл

@ -2,9 +2,8 @@ assert_finish 5, %q{
r, w = IO.pipe
t1 = 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"
sleep 0.1
w.write "a"
}, '[ruby-dev:31866]'
@ -34,9 +33,9 @@ assert_finish 10, %q{
assert_finish 1, %q{
r, w = IO.pipe
Thread.new {
w << "ab"
sleep 0.1
w << "ab"
w << "ab"
sleep 0.01
w << "ab"
}
r.gets("abab")
}
@ -91,7 +90,8 @@ assert_normal_exit %q{
megacontent = "abc" * 12345678
#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
r2, w2 = IO.pipe

Просмотреть файл

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