ruby-changes:34298
From: nobu <ko1@a...>
Date: Sun, 8 Jun 2014 04:57:53 +0900 (JST)
Subject: [ruby-changes:34298] nobu:r46379 (trunk): bootstraptest/test_{fork, io, thread}.rb: reduce sleep times
nobu 2014-06-08 04:57:46 +0900 (Sun, 08 Jun 2014) New Revision: 46379 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46379 Log: bootstraptest/test_{fork,io,thread}.rb: reduce sleep times Modified files: trunk/bootstraptest/test_fork.rb trunk/bootstraptest/test_io.rb trunk/bootstraptest/test_thread.rb Index: bootstraptest/test_fork.rb =================================================================== --- bootstraptest/test_fork.rb (revision 46378) +++ bootstraptest/test_fork.rb (revision 46379) @@ -22,26 +22,32 @@ assert_finish 10, %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_fork.rb#L22 }, '[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{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_fork.rb#L56 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] Index: bootstraptest/test_io.rb =================================================================== --- bootstraptest/test_io.rb (revision 46378) +++ bootstraptest/test_io.rb (revision 46379) @@ -2,9 +2,8 @@ assert_finish 5, %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_io.rb#L2 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{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_io.rb#L33 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{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_io.rb#L90 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 Index: bootstraptest/test_thread.rb =================================================================== --- bootstraptest/test_thread.rb (revision 46378) +++ bootstraptest/test_thread.rb (revision 46379) @@ -241,16 +241,16 @@ assert_equal 'ok', %{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_thread.rb#L241 } 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{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_thread.rb#L276 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{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_thread.rb#L340 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{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_thread.rb#L351 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{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_thread.rb#L369 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{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_thread.rb#L399 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', %{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_thread.rb#L420 rescue NotImplementedError $result = :ok end - END + end; end require "./zzz.rb" $result @@ -448,17 +450,28 @@ assert_finish 3, %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_thread.rb#L450 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 } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/