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

ruby-changes:34027

From: akr <ko1@a...>
Date: Sun, 25 May 2014 14:22:57 +0900 (JST)
Subject: [ruby-changes:34027] akr:r46108 (trunk): * test/openssl: Join threads.

akr	2014-05-25 14:22:49 +0900 (Sun, 25 May 2014)

  New Revision: 46108

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

  Log:
    * test/openssl: Join threads.

  Modified files:
    trunk/ChangeLog
    trunk/test/openssl/test_pair.rb
    trunk/test/openssl/utils.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46107)
+++ ChangeLog	(revision 46108)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun May 25 14:22:30 2014  Tanaka Akira  <akr@f...>
+
+	* test/openssl: Join threads.
+
 Sun May 25 12:46:47 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* error.c (rb_bug_context): new function to report bug with
Index: test/openssl/test_pair.rb
===================================================================
--- test/openssl/test_pair.rb	(revision 46107)
+++ test/openssl/test_pair.rb	(revision 46108)
@@ -83,16 +83,20 @@ end https://github.com/ruby/ruby/blob/trunk/test/openssl/test_pair.rb#L83
 module OpenSSL::TestEOF1M
   def open_file(content)
     s1, s2 = ssl_pair
-    Thread.new { s2 << content; s2.close }
+    th = Thread.new { s2 << content; s2.close }
     yield s1
+  ensure
+    th.join
   end
 end
 
 module OpenSSL::TestEOF2M
   def open_file(content)
     s1, s2 = ssl_pair
-    Thread.new { s1 << content; s1.close }
+    th = Thread.new { s1 << content; s1.close }
     yield s2
+  ensure
+    th.join
   end
 end
 
@@ -317,6 +321,7 @@ module OpenSSL::TestPairM https://github.com/ruby/ruby/blob/trunk/test/openssl/test_pair.rb#L321
     s1.print "a\ndef"
     assert_equal("a\n", s2.gets)
   ensure
+    th.join
     s1.close if s1 && !s1.closed?
     s2.close if s2 && !s2.closed?
     sock1.close if sock1 && !sock1.closed?
Index: test/openssl/utils.rb
===================================================================
--- test/openssl/utils.rb	(revision 46107)
+++ test/openssl/utils.rb	(revision 46108)
@@ -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, server_proc)
+    def server_loop(ctx, ssls, server_proc, threads)
       loop do
         ssl = nil
         begin
@@ -249,10 +249,11 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOP https://github.com/ruby/ruby/blob/trunk/test/openssl/utils.rb#L249
           retry
         end
 
-        Thread.start do
+        th = Thread.start do
           Thread.current.abort_on_exception = true
           server_proc.call(ctx, ssl)
         end
+        threads << th
       end
     rescue Errno::EBADF, IOError, Errno::EINVAL, Errno::ECONNABORTED, Errno::ENOTSOCK, Errno::ECONNRESET
     end
@@ -261,6 +262,7 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOP https://github.com/ruby/ruby/blob/trunk/test/openssl/utils.rb#L262
       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)
@@ -290,7 +292,7 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOP https://github.com/ruby/ruby/blob/trunk/test/openssl/utils.rb#L292
       begin
         server = Thread.new do
           Thread.current.abort_on_exception = true
-          server_loop(ctx, ssls, server_proc)
+          server_loop(ctx, ssls, server_proc, threads)
         end
 
         $stderr.printf("%s started: pid=%d port=%d\n", SSL_SERVER, $$, port) if $DEBUG
@@ -318,6 +320,11 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOP https://github.com/ruby/ruby/blob/trunk/test/openssl/utils.rb#L320
           tcps.close if (tcps)
         end
       end
+    ensure
+      threads.each {|th|
+        th.kill
+        th.join
+      }
     end
 
     def starttls(ssl)

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

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