diff --git a/Gemfile.lock b/Gemfile.lock index 6c1087e..f954106 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -65,7 +65,7 @@ GEM erubi (1.13.0) ethon (0.16.0) ffi (>= 1.15.0) - factbase (0.3.0) + factbase (0.4.0) backtrace (> 0) decoor (> 0) json (~> 2.7) @@ -123,7 +123,7 @@ GEM nokogiri (1.16.7-x86_64-linux) racc (~> 1.4) others (0.0.3) - parallel (1.26.1) + parallel (1.26.2) parser (3.3.4.2) ast (~> 2.4.1) racc @@ -163,7 +163,7 @@ GEM reline (0.5.9) io-console (~> 0.5) retries (0.0.5) - rexml (3.3.4) + rexml (3.3.5) strscan rspec-core (3.13.0) rspec-support (~> 3.13.0) diff --git a/lib/baza-rb.rb b/lib/baza-rb.rb index 25b9e67..bb20ab9 100644 --- a/lib/baza-rb.rb +++ b/lib/baza-rb.rb @@ -428,13 +428,15 @@ def checked(ret, allowed = [200]) allowed = [allowed] unless allowed.is_a?(Array) mtd = (ret.request.original_options[:method] || '???').upcase url = ret.effective_url - log = "#{mtd} #{url} -> #{ret.code}" + raise "#{mtd} #{url} timed out in #{ret.total_time}s" if ret.return_code == :operation_timedout + log = "#{mtd} #{url} -> #{ret.code} (#{format('%0.2f', ret.total_time)}s)" if allowed.include?(ret.code) @loog.debug(log) return ret end @loog.debug("#{log}\n #{(ret.headers || {}).map { |k, v| "#{k}: #{v}" }.join("\n ")}") headers = ret.headers || {} + p ret msg = [ "Invalid response code ##{ret.code} ", "at #{mtd} #{url}", diff --git a/test/test_baza-rb.rb b/test/test_baza-rb.rb index b29fd65..8ab1df1 100644 --- a/test/test_baza-rb.rb +++ b/test/test_baza-rb.rb @@ -215,6 +215,30 @@ def test_push_compression_disabled assert_equal('hello, world!', req.body) end + def test_with_very_short_timeout + WebMock.enable_net_connect! + host = '127.0.0.1' + RandomPort::Pool::SINGLETON.acquire do |port| + server = TCPServer.new(host, port) + t = + Thread.new do + socket = server.accept + req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req.parse(socket) + req.body + sleep 0.1 + socket.puts "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nabc" + socket.close + end + assert( + assert_raises do + BazaRb.new(host, port, '0000', ssl: false, timeout: 0.01).push('x', 'y', []) + end.message.include?('timed out in') + ) + t.join + end + end + private def with_http_server(code, response, opts = {})