about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2012-08-01 13:39:11 -0700
committerEric Wong <normalperson@yhbt.net>2012-08-01 17:14:03 -0700
commitc594b27a194c301519141c8b9e0b88a1df06682a (patch)
tree9b2b703e9330b4f782371c352df477b5b7887bf0
parent53e87bef5bfebe76a8724375902b7c1cfe1636d4 (diff)
downloadmogilefs-client-c594b27a194c301519141c8b9e0b88a1df06682a.tar.gz
This test needs to keep the socket alive on the server to ensure
the client can drop the connection.

We also need to ensure the test fails if the following change is
made:

  --- a/lib/mogilefs/backend.rb
  +++ b/lib/mogilefs/backend.rb
  @@ -255,7 +255,7 @@ def do_request(cmd, args, idempotent = false)
           end
           shutdown_unlocked(true)
         rescue MogileFS::UnreadableSocketError, MogileFS::Timeout
  -        shutdown_unlocked(true)
  +        # shutdown_unlocked(true)
         rescue
           # we DO NOT want the response we timed out waiting for, to crop up later
           # on, on the same socket, intersperesed with a subsequent request!  we

Thanks to David Rasch for inspiring this change.
-rw-r--r--test/test_mogilefs.rb28
1 files changed, 19 insertions, 9 deletions
diff --git a/test/test_mogilefs.rb b/test/test_mogilefs.rb
index 439a045..247feca 100644
--- a/test/test_mogilefs.rb
+++ b/test/test_mogilefs.rb
@@ -616,10 +616,14 @@ class TestMogileFS__MogileFS < TestMogileFS
     received = []
     secs = timeout + 1
     th = Thread.new do
+      close_later = []
       x = a.accept
+      close_later << x
       line = x.gets
       %r{key=(\w+)} =~ line
-      sleep(secs)
+
+      sleep(secs) # cause the client to timeout:
+
       begin
         x.write("OK paths=1&path1=http://0/#{$1}\r\n")
       rescue Errno::EPIPE
@@ -627,21 +631,26 @@ class TestMogileFS__MogileFS < TestMogileFS
         # we don't care either way
       rescue => e
         flunk("#{e.message} (#{e.class})")
-      ensure
-        x.close
       end
       q << :continue_test
 
-      x = a.accept
-      line = x.gets
+      # client should start a new connection here
+      y = a.accept
+      close_later << y
+      line = y.gets
       %r{key=(\w+)} =~ line
       begin
-        x.write("OK paths=1&path1=http://0/#{$1}\r\n")
+        y.write("OK paths=1&path1=http://0/#{$1}\r\n")
       rescue => e
         flunk("#{e.message} (#{e.class})")
-      ensure
-        x.close
       end
+
+      # the client should've killed the old connection:
+      assert_raises(Errno::EPIPE) do
+        loop { x.write("OK paths=1&path1=http://0/#{$1}\r\n") }
+      end
+
+      close_later # main thread closes
     end
     assert_raises(MogileFS::UnreadableSocketError) do
       c.get_paths("a")
@@ -650,7 +659,8 @@ class TestMogileFS__MogileFS < TestMogileFS
     expect2 = %w(http://0/b)
     assert_equal expect2, c.get_paths("b")
     a.close
-    th.join
+    close_later = th.value
+    close_later.each { |io| assert_nil io.close }
   end
 
   def test_idempotent_command_response_truncated