about summary refs log tree commit homepage
path: root/test/test_mogilefs.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_mogilefs.rb')
-rw-r--r--test/test_mogilefs.rb71
1 files changed, 71 insertions, 0 deletions
diff --git a/test/test_mogilefs.rb b/test/test_mogilefs.rb
index d85cbf8..a4dbcd0 100644
--- a/test/test_mogilefs.rb
+++ b/test/test_mogilefs.rb
@@ -568,6 +568,77 @@ class TestMogileFS__MogileFS < TestMogileFS
       sock.close
   end
 
+  def test_idempotent_command_eof
+    ip = "127.0.0.1"
+    a, b = TCPServer.new(ip, 0), TCPServer.new(ip, 0)
+    hosts = [ "#{ip}:#{a.addr[1]}", "#{ip}:#{b.addr[1]}" ]
+    args = { :hosts => hosts, :domain => "foo" }
+    c = MogileFS::MogileFS.new(args)
+    received = []
+    th = Thread.new do
+      r = IO.select([a, b])
+      x = r[0][0].accept
+      received << x.gets
+      x.close
+
+      r = IO.select([a, b])
+      x = r[0][0].accept
+      received << x.gets
+      x.write("OK paths=2&path1=http://0/a&path2=http://0/b\r\n")
+      x.close
+    end
+    expect = %w(http://0/a http://0/b)
+    assert_equal expect, c.get_paths("f")
+    th.join
+    assert_equal 2, received.size
+    assert_equal received[0], received[1]
+  end
+
+  def test_idempotent_command_response_truncated
+    ip = "127.0.0.1"
+    a, b = TCPServer.new(ip, 0), TCPServer.new(ip, 0)
+    hosts = [ "#{ip}:#{a.addr[1]}", "#{ip}:#{b.addr[1]}" ]
+    args = { :hosts => hosts, :domain => "foo" }
+    c = MogileFS::MogileFS.new(args)
+    received = []
+    th = Thread.new do
+      r = IO.select([a, b])
+      x = r[0][0].accept
+      received << x.gets
+      x.write("OK paths=2&path1=http://0/a&path2=http://0/")
+      x.close
+
+      r = IO.select([a, b])
+      x = r[0][0].accept
+      received << x.gets
+      x.write("OK paths=2&path1=http://0/a&path2=http://0/b\r\n")
+      x.close
+    end
+    expect = %w(http://0/a http://0/b)
+    assert_equal expect, c.get_paths("f")
+    th.join
+    assert_equal 2, received.size
+    assert_equal received[0], received[1]
+  end
+
+  def test_non_idempotent_command_eof
+    ip = "127.0.0.1"
+    a, b = TCPServer.new(ip, 0), TCPServer.new(ip, 0)
+    hosts = [ "#{ip}:#{a.addr[1]}", "#{ip}:#{b.addr[1]}" ]
+    args = { :hosts => hosts, :domain => "foo" }
+    c = MogileFS::MogileFS.new(args)
+    received = []
+    th = Thread.new do
+      r = IO.select([a, b])
+      x = r[0][0].accept
+      received << x.gets
+      x.close
+    end
+    assert_raises(EOFError) { c.rename("a", "b") }
+    th.join
+    assert_equal 1, received.size
+  end
+
   def test_sleep
     @backend.sleep = {}
     assert_nothing_raised do