From a1ec69ae682841fdd62a72b6d50df394d407752a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 31 Aug 2016 07:06:55 +0000 Subject: connect_timeout: match :timeout if unset And add some weak tests while we're at it. Actually simulating a connection timeout on localhost will be difficult. --- lib/mogilefs/backend.rb | 2 +- test/test_backend.rb | 17 ++++++++++++++++- 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 -- cgit v1.2.3-24-ge0c7