about summary refs log tree commit homepage
path: root/test/lib_read_write.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/lib_read_write.rb')
-rw-r--r--test/lib_read_write.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/lib_read_write.rb b/test/lib_read_write.rb
index 146c222..e147566 100644
--- a/test/lib_read_write.rb
+++ b/test/lib_read_write.rb
@@ -1,5 +1,7 @@
+# -*- encoding: binary -*-
 require 'test/unit'
 require 'io/nonblock'
+require 'digest/sha1'
 $-w = true
 require 'kgio'
 
@@ -58,6 +60,41 @@ module LibReadWriteTest
     assert false, "should never get here (line:#{__LINE__})"
   end
 
+  def test_trywrite_full
+    buf = "\302\251" * 1024 * 1024
+    buf2 = ""
+    dig = Digest::SHA1.new
+    t = Thread.new do
+      sleep 1
+      nr = 0
+      begin
+        dig.update(@rd.readpartial(4096, buf2))
+        nr += buf2.size
+      rescue EOFError
+        break
+      rescue => e
+      end while true
+      dig.hexdigest
+    end
+    50.times do
+      wr = buf
+      begin
+        rv = @wr.kgio_trywrite(wr)
+        case rv
+        when String
+          wr = rv
+        when Kgio::WaitWritable
+          IO.select(nil, [ @wr ])
+        else
+          wr = false
+        end
+      end while wr
+    end
+    @wr.close
+    t.join
+    assert_equal '8ff79d8115f9fe38d18be858c66aa08a1cc27a66', t.value
+  end
+
   def test_write_conv
     assert_equal nil, @wr.kgio_write(10)
     assert_equal "10", @rd.kgio_read(2)