diff options
-rw-r--r-- | test/test_mogilefs.rb | 28 |
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 |