summaryrefslogtreecommitdiffstats
path: root/test/test_pair.rb
diff options
context:
space:
mode:
authorakr <akr@ruby-lang.org>2014-05-07 12:22:02 +0000
committerakr <akr@ruby-lang.org>2014-05-07 12:22:02 +0000
commit592b99fb1e6a48a6b4a6f485c5114a9b789bb325 (patch)
treea1a65b17b7521383f15258958afef34b5aaee130 /test/test_pair.rb
parent53d9a420874cfa462b3a9cc921bd8fa787c7fa85 (diff)
downloadruby-openssl-history-592b99fb1e6a48a6b4a6f485c5114a9b789bb325.tar.gz
refactoring to extract tcp_pair.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/test_pair.rb')
-rw-r--r--test/test_pair.rb22
1 files changed, 13 insertions, 9 deletions
diff --git a/test/test_pair.rb b/test/test_pair.rb
index 933f612..38b6989 100644
--- a/test/test_pair.rb
+++ b/test/test_pair.rb
@@ -245,19 +245,24 @@ class OpenSSL::TestPair < Test::Unit::TestCase
}
end
- def test_connect_accept_nonblock
+ def tcp_pair
host = "127.0.0.1"
- port = 0
- ctx = OpenSSL::SSL::SSLContext.new()
- ctx.ciphers = "ADH"
- ctx.tmp_dh_callback = proc { OpenSSL::TestUtils::TEST_KEY_DH1024 }
- serv = TCPServer.new(host, port)
-
+ serv = TCPServer.new(host, 0)
port = serv.connect_address.ip_port
-
sock1 = TCPSocket.new(host, port)
sock2 = serv.accept
serv.close
+ [sock1, sock2]
+ ensure
+ serv.close if serv && !serv.closed?
+ end
+
+ def test_connect_accept_nonblock
+ ctx = OpenSSL::SSL::SSLContext.new()
+ ctx.ciphers = "ADH"
+ ctx.tmp_dh_callback = proc { OpenSSL::TestUtils::TEST_KEY_DH1024 }
+
+ sock1, sock2 = tcp_pair
th = Thread.new {
s2 = OpenSSL::SSL::SSLSocket.new(sock2, ctx)
@@ -298,7 +303,6 @@ class OpenSSL::TestPair < Test::Unit::TestCase
ensure
s1.close if s1 && !s1.closed?
s2.close if s2 && !s2.closed?
- serv.close if serv && !serv.closed?
sock1.close if sock1 && !sock1.closed?
sock2.close if sock2 && !sock2.closed?
end