1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

use Timeout.timeout

* time: Object#timeout has been deprecated a long time ago, use
  Timeout.timeout.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-07-13 10:07:01 +00:00
parent 42f1ff1272
commit beb1c085d5
16 changed files with 43 additions and 43 deletions

View file

@ -27,7 +27,7 @@ class DRbService
@server || @@server
end
def self.ext_service(name)
timeout(100, RuntimeError) do
Timeout.timeout(100, RuntimeError) do
manager.service(name)
end
end

View file

@ -53,7 +53,7 @@ class DRbEx
end
def do_timeout(n)
timeout(0.1) do
Timeout.timeout(0.1) do
n.sleep(2)
end
end

View file

@ -28,7 +28,7 @@ class TestIONonblock < Test::Unit::TestCase
w.flush
w << "a" * 4096
result = ""
timeout(10) {
Timeout.timeout(10) {
t0 = Thread.new {
Thread.pass
w.close

View file

@ -292,7 +292,7 @@ module Test
return if @workers.empty?
@workers.reject! do |worker|
begin
timeout(1) do
Timeout.timeout(1) do
worker.quit
end
rescue Errno::EPIPE
@ -303,7 +303,7 @@ module Test
return if @workers.empty?
begin
timeout(0.2 * @workers.size) do
Timeout.timeout(0.2 * @workers.size) do
Process.waitall
end
rescue Timeout::Error

View file

@ -44,7 +44,7 @@ tddwpBAEDjcwMzA5NTYzMTU1MzAwpQMCARM=
end
def test_session
timeout(5) do
Timeout.timeout(5) do
start_server(OpenSSL::SSL::VERIFY_NONE, true) do |server, port|
sock = TCPSocket.new("127.0.0.1", port)
ctx = OpenSSL::SSL::SSLContext.new("TLSv1")
@ -361,7 +361,7 @@ __EOS__
ssl.connect
last_client_session = ssl.session
ssl.close
timeout(5) do
Timeout.timeout(5) do
Thread.pass until called.key?(:new)
assert(called.delete(:new))
Thread.pass until called.key?(:remove)

View file

@ -53,7 +53,7 @@ class TestResolvDNS < Test::Unit::TestCase
}
}
server_thread = Thread.new {
msg, (_, client_port, _, client_address) = timeout(5) {u.recvfrom(4096)}
msg, (_, client_port, _, client_address) = Timeout.timeout(5) {u.recvfrom(4096)}
id, word2, qdcount, ancount, nscount, arcount = msg.unpack("nnnnnn")
qr = (word2 & 0x8000) >> 15
opcode = (word2 & 0x7800) >> 11
@ -160,7 +160,7 @@ class TestResolvDNS < Test::Unit::TestCase
# A rase condition here.
# Another program may use the port.
# But no way to prevent it.
timeout(5) do
Timeout.timeout(5) do
Resolv::DNS.open(:nameserver_port => [[host, port]]) {|dns|
assert_equal([], dns.getresources("test-no-server.example.org", Resolv::DNS::Resource::IN::A))
}

View file

@ -468,7 +468,7 @@ EOT
w.close
end,
proc do |r|
timeout(1) {
Timeout.timeout(1) {
assert_equal("before \xa2\xa2".encode("utf-8", "euc-jp"),
r.gets(rs))
}

View file

@ -1591,7 +1591,7 @@ class TestProcess < Test::Unit::TestCase
with_tmpchdir do
assert_nothing_raised('[ruby-dev:12261]') do
timeout(3) do
Timeout.timeout(3) do
pid = spawn('yes | ls')
Process.waitpid pid
end

View file

@ -51,7 +51,7 @@ class TestReadPartial < Test::Unit::TestCase
assert_equal('ab', r.readpartial(2))
assert_equal('c', r.readpartial(2))
assert_raise(Timeout::Error) {
timeout(0.1) { r.readpartial(2) }
Timeout.timeout(0.1) { r.readpartial(2) }
}
}
end
@ -65,7 +65,7 @@ class TestReadPartial < Test::Unit::TestCase
assert_equal("f\n", r.readpartial(4096))
assert_equal("ghi\n", r.readpartial(4096))
assert_raise(Timeout::Error) {
timeout(0.1) { r.readpartial(2) }
Timeout.timeout(0.1) { r.readpartial(2) }
}
}
end

View file

@ -118,7 +118,7 @@ class TestGemRequestConnectionPool < Gem::TestCase
pool.checkout
t1 = Thread.new {
timeout(1) do
Timeout.timeout(1) do
pool.checkout
end
}

View file

@ -38,7 +38,7 @@ class TestGemStreamUI < Gem::TestCase
skip 'TTY detection broken on windows' if
Gem.win_platform? unless RUBY_VERSION > '1.9.2'
timeout(1) do
Timeout.timeout(1) do
expected_answer = "Arthur, King of the Britons"
@in.string = "#{expected_answer}\n"
actual_answer = @sui.ask("What is your name?")
@ -52,7 +52,7 @@ class TestGemStreamUI < Gem::TestCase
@in.tty = false
timeout(0.1) do
Timeout.timeout(0.1) do
answer = @sui.ask("what is your favorite color?")
assert_equal nil, answer
end
@ -62,7 +62,7 @@ class TestGemStreamUI < Gem::TestCase
skip 'Always uses $stdin on windows' if
Gem.win_platform? unless RUBY_VERSION > '1.9.2'
timeout(1) do
Timeout.timeout(1) do
expected_answer = "Arthur, King of the Britons"
@in.string = "#{expected_answer}\n"
actual_answer = @sui.ask_for_password("What is your name?")
@ -76,7 +76,7 @@ class TestGemStreamUI < Gem::TestCase
@in.tty = false
timeout(0.1) do
Timeout.timeout(0.1) do
answer = @sui.ask_for_password("what is the airspeed velocity of an unladen swallow?")
assert_equal nil, answer
end
@ -88,7 +88,7 @@ class TestGemStreamUI < Gem::TestCase
@in.tty = false
timeout(0.1) do
Timeout.timeout(0.1) do
answer = @sui.ask_yes_no("do coconuts migrate?", false)
assert_equal false, answer
@ -103,7 +103,7 @@ class TestGemStreamUI < Gem::TestCase
@in.tty = false
timeout(0.1) do
Timeout.timeout(0.1) do
assert_raises(Gem::OperationNotSupportedError) do
@sui.ask_yes_no("do coconuts migrate?")
end

View file

@ -102,7 +102,7 @@ class TestSocketNonblock < Test::Unit::TestCase
assert_raise(IO::WaitReadable) { u1.recvfrom_nonblock(100) }
u2.send("", 0, u1.getsockname)
assert_nothing_raised("cygwin 1.5.19 has a problem to send an empty UDP packet. [ruby-dev:28915]") {
timeout(1) { IO.select [u1] }
Timeout.timeout(1) { IO.select [u1] }
}
mesg, inet_addr = u1.recvfrom_nonblock(100)
assert_equal("", mesg)
@ -124,7 +124,7 @@ class TestSocketNonblock < Test::Unit::TestCase
assert_raise(IO::WaitReadable) { u1.recv_nonblock(100) }
u2.send("", 0, u1.getsockname)
assert_nothing_raised("cygwin 1.5.19 has a problem to send an empty UDP packet. [ruby-dev:28915]") {
timeout(1) { IO.select [u1] }
Timeout.timeout(1) { IO.select [u1] }
}
mesg = u1.recv_nonblock(100)
assert_equal("", mesg)

View file

@ -6,7 +6,7 @@ class TestTimeout < Test::Unit::TestCase
def test_queue
q = Queue.new
assert_raise(Timeout::Error, "[ruby-dev:32935]") {
timeout(0.01) { q.pop }
Timeout.timeout(0.01) { q.pop }
}
end
@ -28,7 +28,7 @@ class TestTimeout < Test::Unit::TestCase
bug8730 = '[Bug #8730]'
e = nil
assert_raise_with_message(Timeout::Error, /execution expired/, bug8730) do
timeout 0.01 do
Timeout.timeout 0.01 do
begin
sleep 3
rescue Exception => e
@ -42,7 +42,7 @@ class TestTimeout < Test::Unit::TestCase
exc = Class.new(RuntimeError)
e = nil
assert_nothing_raised(exc) do
timeout 0.01, exc do
Timeout.timeout 0.01, exc do
begin
sleep 3
rescue exc => e
@ -58,10 +58,10 @@ class TestTimeout < Test::Unit::TestCase
def initialize(msg) super end
end
assert_nothing_raised(ArgumentError, bug9354) do
assert_equal(:ok, timeout(100, err) {:ok})
assert_equal(:ok, Timeout.timeout(100, err) {:ok})
end
assert_raise_with_message(err, /execution expired/) do
timeout 0.01, err do
Timeout.timeout 0.01, err do
sleep 3
end
end

View file

@ -22,7 +22,7 @@ module TestParallel
@worker_in.puts "quit"
rescue IOError, Errno::EPIPE
end
timeout(2) do
Timeout.timeout(2) do
Process.waitpid(@worker_pid)
end
rescue Timeout::Error
@ -38,7 +38,7 @@ module TestParallel
end
def test_run
timeout(10) do
Timeout.timeout(10) do
assert_match(/^ready/,@worker_out.gets)
@worker_in.puts "run #{TESTS}/ptest_first.rb test"
assert_match(/^okay/,@worker_out.gets)
@ -49,7 +49,7 @@ module TestParallel
end
def test_run_multiple_testcase_in_one_file
timeout(10) do
Timeout.timeout(10) do
assert_match(/^ready/,@worker_out.gets)
@worker_in.puts "run #{TESTS}/ptest_second.rb test"
assert_match(/^okay/,@worker_out.gets)
@ -62,7 +62,7 @@ module TestParallel
end
def test_accept_run_command_multiple_times
timeout(10) do
Timeout.timeout(10) do
assert_match(/^ready/,@worker_out.gets)
@worker_in.puts "run #{TESTS}/ptest_first.rb test"
assert_match(/^okay/,@worker_out.gets)
@ -80,7 +80,7 @@ module TestParallel
end
def test_p
timeout(10) do
Timeout.timeout(10) do
@worker_in.puts "run #{TESTS}/ptest_first.rb test"
while buf = @worker_out.gets
break if /^p (.+?)$/ =~ buf
@ -90,7 +90,7 @@ module TestParallel
end
def test_done
timeout(10) do
Timeout.timeout(10) do
@worker_in.puts "run #{TESTS}/ptest_forth.rb test"
7.times { @worker_out.gets }
buf = @worker_out.gets
@ -115,7 +115,7 @@ module TestParallel
end
def test_quit
timeout(10) do
Timeout.timeout(10) do
@worker_in.puts "quit"
assert_match(/^bye$/m,@worker_out.read)
end
@ -134,7 +134,7 @@ module TestParallel
def teardown
begin
if @test_pid
timeout(2) do
Timeout.timeout(2) do
Process.waitpid(@test_pid)
end
end
@ -151,40 +151,40 @@ module TestParallel
"--ruby", @options[:ruby].join(" "),
"-j","0", out: File::NULL, err: o)
o.close
timeout(10) {
Timeout.timeout(10) {
assert_match(/Error: parameter of -j option should be greater than 0/,@test_out.read)
}
end
def test_should_run_all_without_any_leaks
spawn_runner
buf = timeout(10){@test_out.read}
buf = Timeout.timeout(10) {@test_out.read}
assert_match(/^[SFE\.]{9}$/,buf)
end
def test_should_retry_failed_on_workers
spawn_runner
buf = timeout(10){@test_out.read}
buf = Timeout.timeout(10) {@test_out.read}
assert_match(/^Retrying\.+$/,buf)
end
def test_no_retry_option
spawn_runner "--no-retry"
buf = timeout(10){@test_out.read}
buf = Timeout.timeout(10) {@test_out.read}
refute_match(/^Retrying\.+$/,buf)
assert_match(/^ +\d+\) Failure:\nTestD#test_fail_at_worker/,buf)
end
def test_jobs_status
spawn_runner "--jobs-status"
buf = timeout(10){@test_out.read}
buf = Timeout.timeout(10) {@test_out.read}
assert_match(/\d+=ptest_(first|second|third|forth) */,buf)
end
def test_separate
# this test depends to --jobs-status
spawn_runner "--jobs-status", "--separate"
buf = timeout(10){@test_out.read}
buf = Timeout.timeout(10) {@test_out.read}
assert(buf.scan(/(\d+?)[:=]/).flatten.uniq.size > 1)
end
end

View file

@ -239,7 +239,7 @@ class TestQueue < Test::Unit::TestCase
sleep 0.1
q << :s
assert_nothing_raised(Timeout::Error) do
timeout(1) { th2.join }
Timeout.timeout(1) { th2.join }
end
ensure
[th1, th2].each do |th|

View file

@ -355,7 +355,7 @@ class TestWEBrickHTTPServer < Test::Unit::TestCase
req = Net::HTTP::Get.new("/")
req['Connection'] = 'Keep-Alive'
begin
timeout(2) do
Timeout.timeout(2) do
http.request(req){|res| assert_equal("foo", res.body) }
end
rescue Timeout::Error