diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2020-02-17 18:47:28 +0000 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2020-02-19 08:23:01 +0000 |
commit | 98f8787b468705dcdb238e24105514bd8a302343 (patch) | |
tree | c945e02a6829bdea626dd314a0e624f60f8a57f5 | |
parent | 9a7bee41eab87c79145c0e97c31a0c4d466a1f2b (diff) | |
download | ruby-openssl-98f8787b468705dcdb238e24105514bd8a302343.tar.gz |
test/openssl/test_ssl: fix random failure in SSLSocket.open test
Let test_socket_open_with_local_address_port_context use a random high
port number and also ignore Errno::EADDRINUSE in case it is in use.
-rw-r--r-- | test/openssl/test_ssl.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/test/openssl/test_ssl.rb b/test/openssl/test_ssl.rb index 3ee7f020..47b3e1d0 100644 --- a/test/openssl/test_ssl.rb +++ b/test/openssl/test_ssl.rb @@ -89,13 +89,17 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase def test_socket_open_with_local_address_port_context start_server { |port| begin + # Guess a free port number + random_port = rand(49152..65535) ctx = OpenSSL::SSL::SSLContext.new - ssl = OpenSSL::SSL::SSLSocket.open("127.0.0.1", port, "127.0.0.1", 8000, context: ctx) + ssl = OpenSSL::SSL::SSLSocket.open("127.0.0.1", port, "127.0.0.1", random_port, context: ctx) ssl.sync_close = true ssl.connect - assert_equal ssl.context, ctx + assert_equal ctx, ssl.context + assert_equal random_port, ssl.io.local_address.ip_port ssl.puts "abc"; assert_equal "abc\n", ssl.gets + rescue Errno::EADDRINUSE ensure ssl&.close end |