about summary refs log tree commit homepage
path: root/test/http_put.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2012-02-01 12:47:19 -0800
committerEric Wong <normalperson@yhbt.net>2012-02-01 13:05:15 -0800
commitb475b5d6734be918b9b2f6d47c4c2bcfc95cf220 (patch)
tree707e012228dbfdb1877bf30af7aafe9ebac2454a /test/http_put.rb
parent97ecfeb02dac5721db0b651336fddd2810d916f0 (diff)
downloadcmogstored-b475b5d6734be918b9b2f6d47c4c2bcfc95cf220.tar.gz
We need to ensure we don't continue until the write buffer is
flushed.  Also fix some potential fd/memory leaks in case we hit
server errors.
Diffstat (limited to 'test/http_put.rb')
-rw-r--r--test/http_put.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/http_put.rb b/test/http_put.rb
index 49d0789..5edd0b4 100644
--- a/test/http_put.rb
+++ b/test/http_put.rb
@@ -9,6 +9,7 @@ require 'fileutils'
 require 'digest/md5'
 require 'net/http'
 require 'stringio'
+require 'io/wait'
 $stderr.sync = $stdout.sync = Thread.abort_on_exception = true
 
 class TestHTTPPut < Test::Unit::TestCase
@@ -232,4 +233,30 @@ class TestHTTPPut < Test::Unit::TestCase
     assert_match(%r{\AHTTP/1\.1 400 Bad Request\r\n}, resp)
     assert( ! File.exist?("#@tmpdir/foo") )
   end
+
+  def test_put_one_way
+    req = "PUT /foo HTTP/1.1\r\n" \
+          "Host: #@host:#@port\r\n" \
+          "Content-Length: 0\r\n" \
+          "\r\n"
+    ok = 0
+    begin
+      nr = @client.write_nonblock(req)
+      if nr == req.size
+        ok += 1
+      end
+    rescue Errno::EAGAIN
+      break
+    end while true
+
+    created = 0
+    while @client.wait(0.5)
+      line = @client.gets
+      if line =~ %r{\AHTTP/1\.1 201 Created}
+        created += 1
+      end
+    end
+    assert_equal ok, created
+    @client.close
+  end
 end