Skip to content

Refactor SSL tests - #1097

Open
rhenium wants to merge 5 commits into
ruby:masterfrom
rhenium:ky/ssl-test-pair-refactor
Open

Refactor SSL tests#1097
rhenium wants to merge 5 commits into
ruby:masterfrom
rhenium:ky/ssl-test-pair-refactor

Conversation

@rhenium

@rhenium rhenium commented Aug 26, 2026

Copy link
Copy Markdown
Member

ssl: move tests for IO-like methods to test_pair.rb

r8081 originally intended test_pair.rb for testing methods that behave
like IO.

Move tests for #{get,read}byte, #sys{read,write}, #close_write, and
IO.copy_stream from test_ssl.rb to test_pair.rb.

Similarly, move tests for methods that are specific to SSLSocket and
not for IO compatibility to test_ssl.rb.


ssl: simplify test_pair.rb

OpenSSL::SSL::SSLSocket only depends on T_FILE and a small number of
methods defined on IO, so the difference between TCPSocket and Socket
is not significant for these tests. Test only one of them to reduce
the test run time by half.

Add a simple client using Socket to test_ssl.rb to keep basic coverage.

Also simplify ut_eof.rb to test only one direction, since the direction
does not matter after the handshake.


ssl: refactor test helper start_server

Break it into multiple pieces and simplify:

  • Let callers pass a complete SSLContext object instead of a
    callback proc ctx_proc to mutate it.

  • Add a variant start_server_proc for tests that need finer control,
    and remove two callbacks server_proc and accept_proc.

  • Remove rescue for IOError, Errno::EBADF, Errno::EINVAL, and
    Errno::ENOTSOCK which as far as I can tell should not be possible.


ssl: delay closing TCP sockets in start_server

Some tests expect server-side SSLSocket#accept to fail for various
reasons. On some systems, closing the underlying socket immediately
with IO#close causes the TCP connection to be terminated with RST.

Do not close it immediately so that the client can reliably receive
the TLS alert. This allows writing more meaningful assertions.

Also add a dedicated test case for the rb_sys_fail() path in
SSLSocket#connect.


ssl: use start_server_proc in more test cases

Update more tests to use start_server_proc instead of UNIXSocket.pair.
It runs threads with timeout and prevents "rake test" from hanging
indefinitely. It also produces better error messages when a test fails.

r8081 originally intended test_pair.rb for testing methods that behave
like IO.

Move tests for #{get,read}byte, #sys{read,write}, #close_write, and
IO.copy_stream from test_ssl.rb to test_pair.rb.

Similarly, move tests for methods that are specific to SSLSocket and
not for IO compatibility to test_ssl.rb.
OpenSSL::SSL::SSLSocket only depends on T_FILE and a small number of
methods defined on IO, so the difference between TCPSocket and Socket
is not significant for these tests. Test only one of them to reduce
the test run time by half.

Add a simple client using Socket to test_ssl.rb to keep basic coverage.

Also simplify ut_eof.rb to test only one direction, since the direction
does not matter after the handshake.
@rhenium
rhenium force-pushed the ky/ssl-test-pair-refactor branch from daf389f to 7063d04 Compare August 26, 2026 13:55
Break it into multiple pieces and simplify:

  - Let callers pass a complete SSLContext object instead of a
    callback proc ctx_proc to mutate it.

  - Add a variant start_server_proc for tests that need finer control,
    and remove two callbacks server_proc and accept_proc.

  - Remove rescue for IOError, Errno::EBADF, Errno::EINVAL, and
    Errno::ENOTSOCK which as far as I can tell should not be possible.
Some tests expect server-side SSLSocket#accept to fail for various
reasons. On some systems, closing the underlying socket immediately
with IO#close causes the TCP connection to be terminated with RST.

Do not close it immediately so that the client can reliably receive
the TLS alert. This allows writing more meaningful assertions.

Also add a dedicated test case for the rb_sys_fail() path in
SSLSocket#connect.
Update more tests to use start_server_proc instead of UNIXSocket.pair.
It runs threads with timeout and prevents "rake test" from hanging
indefinitely. It also produces better error messages when a test fails.
@rhenium rhenium changed the title Refactor test_pair.rb Refactor SSL tests Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant