httpx/regression_tests/bug_1_6_2_test.rb
HoneyryderChuck 9d6b24998c fix: make sure that the native resolver picks up the next timeout of the current hostname being resolved
before, it was evaluating all names in the queue, but that was not accurate due to candidates, so there was always a candidate with a lower timeout; instead, one relies on the preexisting @name, wihch was already point to the currently being resolved name, and use it as proxy to get the correct timeotus list. This also results in performance improvement
2025-10-17 18:53:43 +01:00

46 lines
1.2 KiB
Ruby

# frozen_string_literal: true
require "test_helper"
require "support/http_helpers"
class Bug_1_6_2_Test < Minitest::Test
include HTTPHelpers
def test_recover_well_from_multiple_timeouts_on_persistent
# clear resolver cache
HTTPX::Resolver.lookup_synchronize(&:clear)
start_test_servlet(SlowDNSServer, 1, ttl: 2) do |slow_dns_server|
session = HTTPX.plugin(SessionWithPool)
.plugin(:persistent)
.with(resolver_options: { nameserver: [slow_dns_server.nameserver], timeouts: [1, 3] })
uri = URI(build_uri("/get"))
response = session.get(uri)
verify_status(response, 200)
resolver = session.resolver
assert resolver.tries[uri.host] == 2, "resolving #{uri.host} should have failed the first time"
response = session.get(uri)
verify_status(response, 200)
assert resolver.tries[uri.host] == 2, "name was cached and valid, there should have been no resolution"
sleep 3
response = session.get(uri)
verify_status(response, 200)
assert resolver.tries[uri.host] == 4, "ttl expired, should have resolved in DNS again"
ensure
session.close
end
end
private
def scheme
"http://"
end
end