more timmeout leeway, using Thread.kill instead (truffleruby tests)

This commit is contained in:
HoneyryderChuck 2022-03-29 12:58:30 +01:00
parent c55f03dcb5
commit 5307b33cb6
8 changed files with 34 additions and 61 deletions

View File

@ -72,9 +72,7 @@ class HTTPTest < Minitest::Test
end
def test_max_streams
server = KeepAliveServer.new
th = Thread.new { server.start }
begin
start_test_servlet(KeepAliveServer) do |server|
uri = "#{server.origin}/2"
HTTPX.plugin(SessionWithPool).with(max_concurrent_requests: 1).wrap do |http|
responses = http.get(uri, uri, uri)
@ -82,16 +80,11 @@ class HTTPTest < Minitest::Test
connection_count = http.pool.connection_count
assert connection_count == 2, "expected to have 2 connections, instead have #{connection_count}"
end
ensure
server.shutdown
th.join
end
end
def test_trailers
server = HTTPTrailersServer.new
th = Thread.new { server.start }
begin
start_test_servlet(HTTPTrailersServer) do |server|
uri = "#{server.origin}/"
HTTPX.plugin(SessionWithPool).wrap do |http|
response = http.get(uri)
@ -100,9 +93,6 @@ class HTTPTest < Minitest::Test
verify_header(response.headers, "x-trailer", "hello")
verify_header(response.headers, "x-trailer-2", "world")
end
ensure
server.shutdown
th.join
end
end

View File

@ -136,25 +136,20 @@ class HTTPSTest < Minitest::Test
end
def test_http2_client_sends_settings_timeout
server = SettingsTimeoutServer.new
th = Thread.new { server.accept }
begin
test_server = nil
start_test_servlet(SettingsTimeoutServer) do |server|
test_server = server
uri = "#{server.origin}/"
http = HTTPX.plugin(SessionWithPool).with(timeout: { settings_timeout: 3 }, ssl: { verify_mode: OpenSSL::SSL::VERIFY_NONE })
response = http.get(uri)
verify_error_response(response, HTTPX::SettingsTimeoutError)
ensure
server.shutdown
th.join
end
last_frame = server.frames.last
last_frame = test_server.frames.last
assert last_frame[:error] == :settings_timeout
end
def test_http2_client_goaway_with_no_response
server = KeepAlivePongServer.new
th = Thread.new { server.accept }
begin
start_test_servlet(KeepAlivePongServer) do |server|
uri = "#{server.origin}/"
HTTPX.plugin(SessionWithPool).with(ssl: { verify_mode: OpenSSL::SSL::VERIFY_NONE }) do |http|
response = http.get(uri)
@ -162,9 +157,6 @@ class HTTPSTest < Minitest::Test
response = http.get(uri)
verify_error_response(response, HTTPX::Connection::HTTP2::GoawayError)
end
ensure
server.shutdown
th.join
end
end
end

View File

@ -38,7 +38,7 @@ module ResponseHelpers
delta += if RUBY_ENGINE == "truffleruby"
# truffleruby has a hard time complying reliably with this delta when running in parallel. Therefore,
# we give it a bit of leeway.
10
20
else
# delta checks become very innacurate under multi-thread mode, and elapsed time. we give it some leeway too.
3
@ -98,4 +98,20 @@ module ResponseHelpers
def fixture_file_path
File.join("test", "support", "fixtures", fixture_file_name)
end
def start_test_servlet(servlet_class)
server = servlet_class.new
th = Thread.new { server.start }
begin
yield server
ensure
server.shutdown
begin
Timeout.timeout(3) { th.join }
rescue Timeout::Error
th.kill
end
end
end
end

View File

@ -49,9 +49,7 @@ module Requests
def test_plugin_ntlm_authentication
return if origin.start_with?("https")
server = NTLMServer.new
th = Thread.new { server.start }
begin
start_test_servlet(NTLMServer) do |server|
uri = "#{server.origin}/"
HTTPX.plugin(SessionWithPool).plugin(:ntlm_authentication).wrap do |http|
# skip unless NTLM
@ -65,9 +63,6 @@ module Requests
# invalid_response = http.ntlm_authentication("user", "fake").get(uri)
# verify_status(invalid_response, 401)
end
ensure
server.shutdown
th.join
end
end

View File

@ -90,18 +90,13 @@ module Requests
# run this only for http/1.1 mode, as this is a local test server
return unless origin.start_with?("http://")
server = NoContentLengthServer.new
th = Thread.new { server.start }
begin
start_test_servlet(NoContentLengthServer) do |server|
http = HTTPX.plugin(:compression)
uri = build_uri("/", server.origin)
response = http.get(uri)
verify_status(response, 200)
body = response.body.to_s
assert body == "helloworld"
ensure
server.shutdown
th.join
end
end

View File

@ -17,9 +17,7 @@ module Requests
# run this only for http/1.1 mode, as this is a local test server
return unless origin.start_with?("http://")
server = Expect100Server.new
th = Thread.new { server.start }
begin
start_test_servlet(Expect100Server) do |server|
http = HTTPX.plugin(:expect)
uri = build_uri("/delay?delay=4", server.origin)
response = http.post(uri, body: "helloworld")
@ -30,9 +28,6 @@ module Requests
next_request = http.build_request(:post, build_uri("/", server.origin), body: "helloworld")
verify_header(next_request.headers, "expect", "100-continue")
ensure
server.shutdown
th.join
end
end
@ -54,9 +49,7 @@ module Requests
# run this only for http/1.1 mode, as this is a local test server
return unless origin.start_with?("http://")
server = Expect100Server.new
th = Thread.new { server.start }
begin
start_test_servlet(Expect100Server) do |server|
http = HTTPX.plugin(:expect)
uri = build_uri("/no-expect", server.origin)
response = http.post(uri, body: "helloworld")
@ -67,9 +60,6 @@ module Requests
next_request = http.build_request(:post, build_uri("/", server.origin), body: "helloworld")
verify_no_header(next_request.headers, "expect")
ensure
server.shutdown
th.join
end
end

View File

@ -40,23 +40,18 @@ module Requests
def test_persistent_retry_http2_goaway
return unless origin.start_with?("https")
server = KeepAlivePongServer.new
th = Thread.new { server.accept }
http = HTTPX.plugin(SessionWithPool)
.plugin(RequestInspector)
.plugin(:persistent) # implicit max_retries == 1
.with(ssl: { verify_mode: OpenSSL::SSL::VERIFY_NONE })
begin
start_test_servlet(KeepAlivePongServer) do |server|
http = HTTPX.plugin(SessionWithPool)
.plugin(RequestInspector)
.plugin(:persistent) # implicit max_retries == 1
.with(ssl: { verify_mode: OpenSSL::SSL::VERIFY_NONE })
uri = "#{server.origin}/"
response = http.get(uri)
verify_status(response, 200)
response = http.get(uri)
verify_status(response, 200)
assert http.calls == 2, "expect request to be built 2 times (was #{http.calls})"
ensure
http.close
server.shutdown
th.join
end
end
end

View File

@ -54,7 +54,7 @@ class TestHTTP2Server
@server.close
end
def accept
def start
begin
loop do
sock = @server.accept