diff options
Diffstat (limited to 'test/openssl/test_pair.rb')
-rw-r--r-- | test/openssl/test_pair.rb | 63 |
1 files changed, 57 insertions, 6 deletions
diff --git a/test/openssl/test_pair.rb b/test/openssl/test_pair.rb index fa36725b58..e6b495f669 100644 --- a/test/openssl/test_pair.rb +++ b/test/openssl/test_pair.rb @@ -156,19 +156,46 @@ class OpenSSL::TestPair < Test::Unit::TestCase ret = nil assert_nothing_raised("[ruby-core:20298]") { ret = s2.read_nonblock(10) } assert_equal("def\n", ret) + s1.close + assert_raise(EOFError) { s2.read_nonblock(10) } } end + def test_read_nonblock_no_exception + ssl_pair {|s1, s2| + assert_equal :wait_readable, s2.read_nonblock(10, exception: false) + s1.write "abc\ndef\n" + IO.select([s2]) + assert_equal("ab", s2.read_nonblock(2, exception: false)) + assert_equal("c\n", s2.gets) + ret = nil + assert_nothing_raised("[ruby-core:20298]") { ret = s2.read_nonblock(10, exception: false) } + assert_equal("def\n", ret) + s1.close + assert_equal(nil, s2.read_nonblock(10, exception: false)) + } + end + + def write_nonblock(socket, meth, str) + ret = socket.send(meth, str) + ret.is_a?(Symbol) ? 0 : ret + end + + def write_nonblock_no_ex(socket, str) + ret = socket.write_nonblock str, exception: false + ret.is_a?(Symbol) ? 0 : ret + end + def test_write_nonblock ssl_pair {|s1, s2| n = 0 begin - n += s1.write_nonblock("a" * 100000) - n += s1.write_nonblock("b" * 100000) - n += s1.write_nonblock("c" * 100000) - n += s1.write_nonblock("d" * 100000) - n += s1.write_nonblock("e" * 100000) - n += s1.write_nonblock("f" * 100000) + n += write_nonblock s1, :write_nonblock, "a" * 100000 + n += write_nonblock s1, :write_nonblock, "b" * 100000 + n += write_nonblock s1, :write_nonblock, "c" * 100000 + n += write_nonblock s1, :write_nonblock, "d" * 100000 + n += write_nonblock s1, :write_nonblock, "e" * 100000 + n += write_nonblock s1, :write_nonblock, "f" * 100000 rescue IO::WaitWritable end s1.close @@ -176,6 +203,20 @@ class OpenSSL::TestPair < Test::Unit::TestCase } end + def test_write_nonblock_no_exceptions + ssl_pair {|s1, s2| + n = 0 + n += write_nonblock_no_ex s1, "a" * 100000 + n += write_nonblock_no_ex s1, "b" * 100000 + n += write_nonblock_no_ex s1, "c" * 100000 + n += write_nonblock_no_ex s1, "d" * 100000 + n += write_nonblock_no_ex s1, "e" * 100000 + n += write_nonblock_no_ex s1, "f" * 100000 + s1.close + assert_equal(n, s2.read.length) + } + end + def test_write_nonblock_with_buffered_data ssl_pair {|s1, s2| s1.write "foo" @@ -186,6 +227,16 @@ class OpenSSL::TestPair < Test::Unit::TestCase } end + def test_write_nonblock_with_buffered_data_no_exceptions + ssl_pair {|s1, s2| + s1.write "foo" + s1.write_nonblock("bar", exception: false) + s1.write "baz" + s1.close + assert_equal("foobarbaz", s2.read) + } + end + def test_connect_accept_nonblock host = "127.0.0.1" port = 0 |