From 98f8787b468705dcdb238e24105514bd8a302343 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Mon, 17 Feb 2020 18:47:28 +0000 Subject: 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. --- test/openssl/test_ssl.rb | 8 ++++++-- 1 file 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 -- cgit v1.2.3