summaryrefslogtreecommitdiff
path: root/bootstraptest/test_thread.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-07 19:57:46 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-07 19:57:46 +0000
commit85521e60eef7eee999cf1c0c0e460cabdeaa6f7f (patch)
tree45a563ae8fba7d02fcbf26958150b06bacba83f3 /bootstraptest/test_thread.rb
parent7d8fc3696ef8fa9f600d1943afe2f525debc5564 (diff)
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
Diffstat (limited to 'bootstraptest/test_thread.rb')
-rw-r--r--bootstraptest/test_thread.rb57
1 files changed, 35 insertions, 22 deletions
diff --git a/bootstraptest/test_thread.rb b/bootstraptest/test_thread.rb
index 7baa806..a6e76c2 100644
--- a/bootstraptest/test_thread.rb
+++ b/bootstraptest/test_thread.rb
@@ -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
}