about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-08-31 07:06:55 +0000
committerEric Wong <e@80x24.org>2016-08-31 07:08:14 +0000
commita1ec69ae682841fdd62a72b6d50df394d407752a (patch)
tree3bd74820f9f904db5ce480f02c2690eb4b8d89bb
parent68e8a22d5eafae68caefdee248891ac523f48033 (diff)
downloadmogilefs-client-a1ec69ae682841fdd62a72b6d50df394d407752a.tar.gz
And add some weak tests while we're at it.
Actually simulating a connection timeout on localhost
will be difficult.
-rw-r--r--lib/mogilefs/backend.rb2
-rw-r--r--test/test_backend.rb17
2 files changed, 17 insertions, 2 deletions
diff --git a/lib/mogilefs/backend.rb b/lib/mogilefs/backend.rb
index 4cf2526..7f91508 100644
--- a/lib/mogilefs/backend.rb
+++ b/lib/mogilefs/backend.rb
@@ -79,7 +79,7 @@ class MogileFS::Backend
 
     @mutex = Mutex.new
     @timeout = args[:timeout] || 3
-    @connect_timeout = args[:connect_timeout] || 3
+    @connect_timeout = args[:connect_timeout] || @timeout
     @socket = nil
     @lasterr = nil
     @lasterrstr = nil
diff --git a/test/test_backend.rb b/test/test_backend.rb
index 2078e9b..4d41354 100644
--- a/test/test_backend.rb
+++ b/test/test_backend.rb
@@ -25,12 +25,14 @@ class TestBackend < Test::Unit::TestCase
 
     assert_equal ['localhost:1'], @backend.hosts
     assert_equal 3, @backend.timeout
+    assert_equal 3, @backend.instance_variable_get(:@connect_timeout)
     assert_equal nil, @backend.lasterr
     assert_equal nil, @backend.lasterrstr
     assert_equal({}, @backend.dead)
 
     @backend = MogileFS::Backend.new :hosts => ['localhost:6001'], :timeout => 1
     assert_equal 1, @backend.timeout
+    assert_equal 1, @backend.instance_variable_get(:@connect_timeout)
   end
 
   def test_do_request
@@ -223,5 +225,18 @@ class TestBackend < Test::Unit::TestCase
     c = MogileFS::MogileFS.new(o)
     assert_equal 0.666, c.backend.instance_variable_get(:@fail_timeout)
   end
-end
 
+  def test_connect_timeout
+    o = {
+      :domain => "none",
+      :hosts => %w(0:666 0:6 0:66),
+      :connect_timeout => 1
+    }
+    c = MogileFS::MogileFS.new(o)
+    assert_equal 1, c.backend.instance_variable_get(:@connect_timeout)
+    o[:timeout] = 5
+    c = MogileFS::MogileFS.new(o)
+    assert_equal 1, c.backend.instance_variable_get(:@connect_timeout)
+    assert_equal 5, c.backend.instance_variable_get(:@timeout)
+  end
+end