diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2017-09-04 17:19:58 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2017-09-04 17:19:58 +0900 |
commit | 8ed81ff4b0a893376f949c006942fea8f7fba8c3 (patch) | |
tree | a9540da3ca47db407ab9bd9d6256b0c91266742f | |
parent | 230467d23c2b70f2f8f1af1e5b28243e0e119cf6 (diff) | |
download | ruby-openssl-8ed81ff4b0a893376f949c006942fea8f7fba8c3.tar.gz |
test/test_pair: fix test_write_nonblock{,_no_exceptions}ky/fix-test-pair-write-nonblock
When the previous SSLSocket#write_nonblock call does not finish writing
the complete contents, SSL_shutdown() which is called through
SSLSocket#close will not send a close_notify alert.
As of commit e3a305063675 ssl_pair no longer uses the sync_close
feature. Do not expect that SSL_read() would get ECONNRESET.
-rw-r--r-- | test/test_pair.rb | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/test/test_pair.rb b/test/test_pair.rb index 2fb7726d..7e2a4a63 100644 --- a/test/test_pair.rb +++ b/test/test_pair.rb @@ -238,44 +238,42 @@ module OpenSSL::TestPairM } 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 += 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 + assert_equal 3, s1.write_nonblock("foo") + assert_equal "foo", s2.read(3) + + data = "x" * 16384 + written = 0 + while true + begin + written += s1.write_nonblock(data) + rescue IO::WaitWritable, IO::WaitReadable + break + end end - s1.close - assert_equal(n, s2.read.length) + assert written > 0 + assert_equal written, s2.read(written).bytesize } 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) + assert_equal 3, s1.write_nonblock("foo", exception: false) + assert_equal "foo", s2.read(3) + + data = "x" * 16384 + written = 0 + while true + case ret = s1.write_nonblock(data, exception: false) + when :wait_readable, :wait_writable + break + else + written += ret + end + end + assert written > 0 + assert_equal written, s2.read(written).bytesize } end |