From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id B50D91FD99; Wed, 31 Aug 2016 07:09:51 +0000 (UTC) Date: Wed, 31 Aug 2016 07:09:51 +0000 From: Eric Wong To: mogilefs-client-public@bogomips.org Subject: [7/6 PATCH] connect_timeout: match :timeout if unset Message-ID: <20160831070951.GA7205@starla> References: <20160831025046.24153-1-e@80x24.org> <20160831025046.24153-5-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20160831025046.24153-5-e@80x24.org> List-Id: 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 @@ def initialize(args) @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 @@ def test_initialize 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 @@ def test_fail_timeout 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 -- EW