Skip to content

Commit

Permalink
#6 show timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Aug 13, 2024
1 parent 54e8f6d commit 43618e6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion lib/baza-rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
24 changes: 24 additions & 0 deletions test/test_baza-rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {})
Expand Down

1 comment on commit 43618e6

@0crat
Copy link

@0crat 0crat commented on 43618e6 Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yegor256 It is not a good idea to push directly to the default branch master. You've earned -20 points. Next time, create a new branch, push your changes over there, then make a pull request and merge it. Even if you are flying solo, contributing via pull requests is a good practice. Your running balance is -526.

Please sign in to comment.