[前][次][番号順一覧][スレッド一覧]

ruby-changes:39144

From: nobu <ko1@a...>
Date: Mon, 13 Jul 2015 19:07:17 +0900 (JST)
Subject: [ruby-changes:39144] nobu:r51225 (trunk): use Timeout.timeout

nobu	2015-07-13 19:07:01 +0900 (Mon, 13 Jul 2015)

  New Revision: 51225

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51225

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

  Modified files:
    trunk/test/drb/drbtest.rb
    trunk/test/drb/ut_drb.rb
    trunk/test/io/nonblock/test_flush.rb
    trunk/test/lib/test/unit.rb
    trunk/test/openssl/test_ssl_session.rb
    trunk/test/resolv/test_dns.rb
    trunk/test/ruby/test_io_m17n.rb
    trunk/test/ruby/test_process.rb
    trunk/test/ruby/test_readpartial.rb
    trunk/test/rubygems/test_gem_request_connection_pools.rb
    trunk/test/rubygems/test_gem_stream_ui.rb
    trunk/test/socket/test_nonblock.rb
    trunk/test/test_timeout.rb
    trunk/test/testunit/test_parallel.rb
    trunk/test/thread/test_queue.rb
    trunk/test/webrick/test_httpserver.rb
Index: test/ruby/test_io_m17n.rb
===================================================================
--- test/ruby/test_io_m17n.rb	(revision 51224)
+++ test/ruby/test_io_m17n.rb	(revision 51225)
@@ -468,7 +468,7 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io_m17n.rb#L468
            w.close
          end,
          proc do |r|
-           timeout(1) {
+           Timeout.timeout(1) {
              assert_equal("before \xa2\xa2".encode("utf-8", "euc-jp"),
                           r.gets(rs))
            }
Index: test/ruby/test_readpartial.rb
===================================================================
--- test/ruby/test_readpartial.rb	(revision 51224)
+++ test/ruby/test_readpartial.rb	(revision 51225)
@@ -51,7 +51,7 @@ class TestReadPartial < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_readpartial.rb#L51
       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::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_readpartial.rb#L65
       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
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 51224)
+++ test/ruby/test_process.rb	(revision 51225)
@@ -1591,7 +1591,7 @@ class TestProcess < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L1591
 
     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
Index: test/thread/test_queue.rb
===================================================================
--- test/thread/test_queue.rb	(revision 51224)
+++ test/thread/test_queue.rb	(revision 51225)
@@ -239,7 +239,7 @@ class TestQueue < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/thread/test_queue.rb#L239
     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|
Index: test/testunit/test_parallel.rb
===================================================================
--- test/testunit/test_parallel.rb	(revision 51224)
+++ test/testunit/test_parallel.rb	(revision 51225)
@@ -22,7 +22,7 @@ module TestParallel https://github.com/ruby/ruby/blob/trunk/test/testunit/test_parallel.rb#L22
             @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 https://github.com/ruby/ruby/blob/trunk/test/testunit/test_parallel.rb#L38
     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 https://github.com/ruby/ruby/blob/trunk/test/testunit/test_parallel.rb#L49
     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 https://github.com/ruby/ruby/blob/trunk/test/testunit/test_parallel.rb#L62
     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 https://github.com/ruby/ruby/blob/trunk/test/testunit/test_parallel.rb#L80
     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 https://github.com/ruby/ruby/blob/trunk/test/testunit/test_parallel.rb#L90
     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 https://github.com/ruby/ruby/blob/trunk/test/testunit/test_parallel.rb#L115
     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 https://github.com/ruby/ruby/blob/trunk/test/testunit/test_parallel.rb#L134
     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 https://github.com/ruby/ruby/blob/trunk/test/testunit/test_parallel.rb#L151
                         "--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
Index: test/openssl/test_ssl_session.rb
===================================================================
--- test/openssl/test_ssl_session.rb	(revision 51224)
+++ test/openssl/test_ssl_session.rb	(revision 51225)
@@ -44,7 +44,7 @@ tddwpBAEDjcwMzA5NTYzMTU1MzAwpQMCARM= https://github.com/ruby/ruby/blob/trunk/test/openssl/test_ssl_session.rb#L44
   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__ https://github.com/ruby/ruby/blob/trunk/test/openssl/test_ssl_session.rb#L361
           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)
Index: test/webrick/test_httpserver.rb
===================================================================
--- test/webrick/test_httpserver.rb	(revision 51224)
+++ test/webrick/test_httpserver.rb	(revision 51225)
@@ -355,7 +355,7 @@ class TestWEBrickHTTPServer < Test::Unit https://github.com/ruby/ruby/blob/trunk/test/webrick/test_httpserver.rb#L355
       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
Index: test/rubygems/test_gem_stream_ui.rb
===================================================================
--- test/rubygems/test_gem_stream_ui.rb	(revision 51224)
+++ test/rubygems/test_gem_stream_ui.rb	(revision 51225)
@@ -38,7 +38,7 @@ class TestGemStreamUI < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_stream_ui.rb#L38
     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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_stream_ui.rb#L52
 
     @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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_stream_ui.rb#L62
     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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_stream_ui.rb#L76
 
     @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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_stream_ui.rb#L88
 
     @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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_stream_ui.rb#L103
 
     @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
Index: test/rubygems/test_gem_request_connection_pools.rb
===================================================================
--- test/rubygems/test_gem_request_connection_pools.rb	(revision 51224)
+++ test/rubygems/test_gem_request_connection_pools.rb	(revision 51225)
@@ -118,7 +118,7 @@ class TestGemRequestConnectionPool < Gem https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_request_connection_pools.rb#L118
     pool.checkout
 
     t1 = Thread.new {
-      timeout(1) do
+      Timeout.timeout(1) do
         pool.checkout
       end
     }
Index: test/resolv/test_dns.rb
===================================================================
--- test/resolv/test_dns.rb	(revision 51224)
+++ test/resolv/test_dns.rb	(revision 51225)
@@ -53,7 +53,7 @@ class TestResolvDNS < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/resolv/test_dns.rb#L53
           }
         }
         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::TestCa https://github.com/ruby/ruby/blob/trunk/test/resolv/test_dns.rb#L160
     # 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))
       }
Index: test/test_timeout.rb
===================================================================
--- test/test_timeout.rb	(revision 51224)
+++ test/test_timeout.rb	(revision 51225)
@@ -6,7 +6,7 @@ class TestTimeout < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_timeout.rb#L6
   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 https://github.com/ruby/ruby/blob/trunk/test/test_timeout.rb#L28
     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 https://github.com/ruby/ruby/blob/trunk/test/test_timeout.rb#L42
     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 https://github.com/ruby/ruby/blob/trunk/test/test_timeout.rb#L58
       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
Index: test/lib/test/unit.rb
===================================================================
--- test/lib/test/unit.rb	(revision 51224)
+++ test/lib/test/unit.rb	(revision 51225)
@@ -292,7 +292,7 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit.rb#L292
         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 https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit.rb#L303
 
         return if @workers.empty?
         begin
-          timeout(0.2 * @workers.size) do
+          Timeout.timeout(0.2 * @workers.size) do
             Process.waitall
           end
         rescue Timeout::Error
Index: test/socket/test_nonblock.rb
===================================================================
--- test/socket/test_nonblock.rb	(revision 51224)
+++ test/socket/test_nonblock.rb	(revision 51225)
@@ -102,7 +102,7 @@ class TestSocketNonblock < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/test/socket/test_nonblock.rb#L102
     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::T https://github.com/ruby/ruby/blob/trunk/test/socket/test_nonblock.rb#L124
     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)
Index: test/drb/ut_drb.rb
===================================================================
--- test/drb/ut_drb.rb	(revision 51224)
+++ test/drb/ut_drb.rb	(revision 51225)
@@ -53,7 +53,7 @@ class DRbEx https://github.com/ruby/ruby/blob/trunk/test/drb/ut_drb.rb#L53
   end
 
   def do_timeout(n)
-    timeout(0.1) do
+    Timeout.timeout(0.1) do
       n.sleep(2)
     end
   end
Index: test/drb/drbtest.rb
===================================================================
--- test/drb/drbtest.rb	(revision 51224)
+++ test/drb/drbtest.rb	(revision 51225)
@@ -27,7 +27,7 @@ class DRbService https://github.com/ruby/ruby/blob/trunk/test/drb/drbtest.rb#L27
     @server || @@server
   end
   def self.ext_service(name)
-    timeout(100, RuntimeError) do
+    Timeout.timeout(100, RuntimeError) do
       manager.service(name)
     end
   end
Index: test/io/nonblock/test_flush.rb
===================================================================
--- test/io/nonblock/test_flush.rb	(revision 51224)
+++ test/io/nonblock/test_flush.rb	(revision 51225)
@@ -28,7 +28,7 @@ class TestIONonblock < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/io/nonblock/test_flush.rb#L28
     w.flush
     w << "a" * 4096
     result = ""
-    timeout(10) {
+    Timeout.timeout(10) {
       t0 = Thread.new {
         Thread.pass
         w.close

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]