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

ruby-changes:36144

From: akr <ko1@a...>
Date: Sat, 1 Nov 2014 22:10:44 +0900 (JST)
Subject: [ruby-changes:36144] akr:r48225 (trunk): * test/openssl/test_ssl_session.rb (test_ctx_client_session_cb): Don't

akr	2014-11-01 22:10:37 +0900 (Sat, 01 Nov 2014)

  New Revision: 48225

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

  Log:
    * test/openssl/test_ssl_session.rb (test_ctx_client_session_cb): Don't
      ignore errors of SSL accept.
      (test_ctx_server_session_cb): Ditto.
    
    * test/openssl/utils.rb (server_loop): Add ignore_ssl_accept_error
      argument.
      (start_server): Refine threads waits.
    
    * test/ruby/envutil.rb (assert_join_threads): Show a thread before
      backtrace.

  Modified files:
    trunk/ChangeLog
    trunk/test/openssl/test_ssl_session.rb
    trunk/test/openssl/utils.rb
    trunk/test/ruby/envutil.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48224)
+++ ChangeLog	(revision 48225)
@@ -1,3 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Nov  1 22:06:24 2014  Tanaka Akira  <akr@f...>
+
+	* test/openssl/test_ssl_session.rb (test_ctx_client_session_cb): Don't
+	  ignore errors of SSL accept.
+	  (test_ctx_server_session_cb): Ditto.
+
+	* test/openssl/utils.rb (server_loop): Add ignore_ssl_accept_error
+	  argument.
+	  (start_server): Refine threads waits.
+
+	* test/ruby/envutil.rb (assert_join_threads): Show a thread before
+	  backtrace.
+
 Sat Nov  1 20:40:18 2014  Tanaka Akira  <akr@f...>
 
 	* test/openssl/utils.rb (start_server, server_loop): Use a
Index: test/ruby/envutil.rb
===================================================================
--- test/ruby/envutil.rb	(revision 48224)
+++ test/ruby/envutil.rb	(revision 48225)
@@ -529,13 +529,14 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/envutil.rb#L529
           begin
             values << th.value
           rescue Exception
-            errs << $!
+            errs << [th, $!]
           end
         end
         if !errs.empty?
-          msg = errs.map {|err|
+          msg = errs.map {|t, err|
             err.backtrace.map.with_index {|line, i|
               if i == 0
+                "#{t.inspect}:\n" +
                 "#{line}: #{err.message} (#{err.class})"
               else
                 "\tfrom #{line}"
Index: test/openssl/utils.rb
===================================================================
--- test/openssl/utils.rb	(revision 48224)
+++ test/openssl/utils.rb	(revision 48225)
@@ -240,7 +240,7 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOP https://github.com/ruby/ruby/blob/trunk/test/openssl/utils.rb#L240
       ssl.close rescue nil
     end
 
-    def server_loop(ctx, ssls, stop_pipe_r, server_proc, threads)
+    def server_loop(ctx, ssls, stop_pipe_r, ignore_ssl_accept_error, server_proc, threads)
       loop do
         ssl = nil
         begin
@@ -250,11 +250,14 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOP https://github.com/ruby/ruby/blob/trunk/test/openssl/utils.rb#L250
           end
           ssl = ssls.accept
         rescue OpenSSL::SSL::SSLError
-          retry
+          if ignore_ssl_accept_error
+            retry
+          else
+            raise
+          end
         end
 
         th = Thread.start do
-          Thread.current.abort_on_exception = true
           server_proc.call(ctx, ssl)
         end
         threads << th
@@ -263,65 +266,63 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOP https://github.com/ruby/ruby/blob/trunk/test/openssl/utils.rb#L266
     end
 
     def start_server(port0, verify_mode, start_immediately, args = {}, &block)
-      ctx_proc = args[:ctx_proc]
-      server_proc = args[:server_proc]
-      server_proc ||= method(:readwrite_loop)
-      threads = []
-
-      store = OpenSSL::X509::Store.new
-      store.add_cert(@ca_cert)
-      store.purpose = OpenSSL::X509::PURPOSE_SSL_CLIENT
-      ctx = OpenSSL::SSL::SSLContext.new
-      ctx.cert_store = store
-      #ctx.extra_chain_cert = [ ca_cert ]
-      ctx.cert = @svr_cert
-      ctx.key = @svr_key
-      ctx.tmp_dh_callback = proc { OpenSSL::TestUtils::TEST_KEY_DH1024 }
-      ctx.verify_mode = verify_mode
-      ctx_proc.call(ctx) if ctx_proc
-
-      Socket.do_not_reverse_lookup = true
-      tcps = nil
-      port = port0
-      begin
-        tcps = TCPServer.new("127.0.0.1", port)
-      rescue Errno::EADDRINUSE
-        port += 1
-        retry
-      end
-
-      stop_pipe_r, stop_pipe_w = IO.pipe
+      IO.pipe {|stop_pipe_r, stop_pipe_w|
+        begin
+          ctx_proc = args[:ctx_proc]
+          server_proc = args[:server_proc]
+          ignore_ssl_accept_error = args.fetch(:ignore_ssl_accept_error, true)
+          server_proc ||= method(:readwrite_loop)
+          threads = []
+
+          store = OpenSSL::X509::Store.new
+          store.add_cert(@ca_cert)
+          store.purpose = OpenSSL::X509::PURPOSE_SSL_CLIENT
+          ctx = OpenSSL::SSL::SSLContext.new
+          ctx.cert_store = store
+          #ctx.extra_chain_cert = [ ca_cert ]
+          ctx.cert = @svr_cert
+          ctx.key = @svr_key
+          ctx.tmp_dh_callback = proc { OpenSSL::TestUtils::TEST_KEY_DH1024 }
+          ctx.verify_mode = verify_mode
+          ctx_proc.call(ctx) if ctx_proc
+
+          Socket.do_not_reverse_lookup = true
+          tcps = nil
+          port = port0
+          begin
+            tcps = TCPServer.new("127.0.0.1", port)
+          rescue Errno::EADDRINUSE
+            port += 1
+            retry
+          end
 
-      ssls = OpenSSL::SSL::SSLServer.new(tcps, ctx)
-      ssls.start_immediately = start_immediately
+          ssls = OpenSSL::SSL::SSLServer.new(tcps, ctx)
+          ssls.start_immediately = start_immediately
 
-      begin
-        server = Thread.new do
-          Thread.current.abort_on_exception = true
-          server_loop(ctx, ssls, stop_pipe_r, server_proc, threads)
-        end
+          server = Thread.new do
+            server_loop(ctx, ssls, stop_pipe_r, ignore_ssl_accept_error, server_proc, threads)
+          end
+          threads.unshift server
 
-        $stderr.printf("%s started: pid=%d port=%d\n", SSL_SERVER, $$, port) if $DEBUG
+          $stderr.printf("%s started: pid=%d port=%d\n", SSL_SERVER, $$, port) if $DEBUG
 
-        block.call(server, port.to_i)
-      ensure
-        begin
-          stop_pipe_w.close
-          if (server)
-            server.join(5)
-            if server.alive?
-              server.join
-              flunk("TCPServer was closed and SSLServer is still alive") unless $!
+          th = Thread.new do
+            begin
+              block.call(server, port.to_i)
+            ensure
+              stop_pipe_w.close
             end
           end
+          begin
+            th.join
+          rescue Exception
+            threads.unshift th
+          end
         ensure
-          tcps.close if (tcps)
+          tcps.close if tcps
+          assert_join_threads(threads)
         end
-      end
-    ensure
-      stop_pipe_r.close if !stop_pipe_r.closed?
-      stop_pipe_w.close if !stop_pipe_w.closed?
-      assert_join_threads(threads)
+      }
     end
 
     def starttls(ssl)
Index: test/openssl/test_ssl_session.rb
===================================================================
--- test/openssl/test_ssl_session.rb	(revision 48224)
+++ test/openssl/test_ssl_session.rb	(revision 48225)
@@ -289,18 +289,22 @@ __EOS__ https://github.com/ruby/ruby/blob/trunk/test/openssl/test_ssl_session.rb#L289
       # any resulting value is OK (ignored)
     }
 
-    start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true) do |server, port|
+    start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true, ignore_ssl_accept_error: false) do |server, port|
       sock = TCPSocket.new("127.0.0.1", port)
-      ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
-      ssl.sync_close = true
-      ssl.connect
-      assert_equal(1, ctx.session_cache_stats[:cache_num])
-      assert_equal(1, ctx.session_cache_stats[:connect_good])
-      assert_equal([ssl, ssl.session], called[:new])
-      assert(ctx.session_remove(ssl.session))
-      assert(!ctx.session_remove(ssl.session))
-      assert_equal([ctx, ssl.session], called[:remove])
-      ssl.close
+      begin
+        ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
+        ssl.sync_close = true
+        ssl.connect
+        assert_equal(1, ctx.session_cache_stats[:cache_num])
+        assert_equal(1, ctx.session_cache_stats[:connect_good])
+        assert_equal([ssl, ssl.session], called[:new])
+        assert(ctx.session_remove(ssl.session))
+        assert(!ctx.session_remove(ssl.session))
+        assert_equal([ctx, ssl.session], called[:remove])
+        ssl.close
+      ensure
+        sock.close if !sock.closed?
+      end
     end
   end
 
@@ -343,21 +347,25 @@ __EOS__ https://github.com/ruby/ruby/blob/trunk/test/openssl/test_ssl_session.rb#L347
       c.session_cache_stats
       readwrite_loop(c, ssl)
     }
-    start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true, :ctx_proc => ctx_proc, :server_proc => server_proc) do |server, port|
+    start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true, ctx_proc: ctx_proc, server_proc: server_proc, ignore_ssl_accept_error: false) do |server, port|
       last_client_session = nil
       3.times do
         sock = TCPSocket.new("127.0.0.1", port)
-        ssl = OpenSSL::SSL::SSLSocket.new(sock, OpenSSL::SSL::SSLContext.new("SSLv3"))
-        ssl.sync_close = true
-        ssl.session = last_client_session if last_client_session
-        ssl.connect
-        last_client_session = ssl.session
-        ssl.close
-        timeout(5) do
-          Thread.pass until called.key?(:new)
-          assert(called.delete(:new))
-          Thread.pass until called.key?(:remove)
-          assert(called.delete(:remove))
+        begin
+          ssl = OpenSSL::SSL::SSLSocket.new(sock, OpenSSL::SSL::SSLContext.new("SSLv3"))
+          ssl.sync_close = true
+          ssl.session = last_client_session if last_client_session
+          ssl.connect
+          last_client_session = ssl.session
+          ssl.close
+          timeout(5) do
+            Thread.pass until called.key?(:new)
+            assert(called.delete(:new))
+            Thread.pass until called.key?(:remove)
+            assert(called.delete(:remove))
+          end
+        ensure
+          sock.close if !sock.closed?
         end
       end
     end

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

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