mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-13 00:02:57 -04:00
fixed tests for connect timeouts
using ip tables to drop SYN packets on port 9090; this requires to run the container in privileged mode. It was also necessary to handle the Errno::ETIMEDOUT error, as this has to be directly transformed into a connection error
This commit is contained in:
parent
881a81cb46
commit
b96eb526a3
@ -21,6 +21,7 @@ services:
|
||||
- BUNDLE_APP_CONFIG=/usr/local/bundle
|
||||
- HTTPBIN_ALTSVC_HOST=another2
|
||||
image: ruby:alpine
|
||||
privileged: true
|
||||
depends_on:
|
||||
- httpproxy
|
||||
- socksproxy
|
||||
@ -67,7 +68,7 @@ services:
|
||||
volumes:
|
||||
- ./test/support/ci:/home
|
||||
command:
|
||||
--conf /home/nghttp.conf --no-ocsp --frontend-frame-debug --frontend 0.0.0.0,80;no-tls --frontend 0.0.0.0,443
|
||||
--conf /home/nghttp.conf --no-ocsp --frontend 0.0.0.0,80;no-tls --frontend 0.0.0.0,443
|
||||
|
||||
altsvc-nghttp2:
|
||||
image: registry.gitlab.com/honeyryderchuck/httpx/nghttp2:2
|
||||
|
@ -64,6 +64,11 @@ module HTTPX
|
||||
rescue Errno::EHOSTUNREACH => e
|
||||
raise e if @ip_index <= 0
|
||||
|
||||
@ip_index -= 1
|
||||
retry
|
||||
rescue Errno::ETIMEDOUT => e
|
||||
raise ConnectTimeout, e.message if @ip_index <= 0
|
||||
|
||||
@ip_index -= 1
|
||||
retry
|
||||
rescue Errno::EINPROGRESS,
|
||||
|
@ -3,13 +3,16 @@
|
||||
RUBY_PLATFORM=`ruby -e 'puts RUBY_PLATFORM'`
|
||||
|
||||
if [[ "$RUBY_PLATFORM" = "java" ]]; then
|
||||
apk --update add git bash
|
||||
apk --update add git bash iptables
|
||||
elif [[ ${RUBY_VERSION:0:3} = "2.1" ]]; then
|
||||
apk --update add g++ make git bash libsodium
|
||||
apk --update add g++ make git bash libsodium iptables
|
||||
else
|
||||
apk --update add g++ make git bash
|
||||
apk --update add g++ make git bash iptables
|
||||
fi
|
||||
|
||||
# use port 9090 to test connection timeouts
|
||||
iptables -A OUTPUT -p tcp -m tcp --tcp-flags SYN SYN --sport 9090 -j DROP
|
||||
|
||||
export PATH=$GEM_HOME/bin:$BUNDLE_PATH/gems/bin:$PATH
|
||||
mkdir -p "$GEM_HOME" && chmod 777 "$GEM_HOME"
|
||||
gem install bundler -v="1.17.3" --no-doc --conservative
|
||||
|
@ -19,7 +19,7 @@ module Requests
|
||||
end
|
||||
|
||||
def test_http_timeout_connect_timeout
|
||||
uri = "#{origin("nghttp2.org")}:81"
|
||||
uri = build_uri("/", origin("127.0.0.1:9090"))
|
||||
session = HTTPX.timeout(connect_timeout: 0.5, operation_timeout: 30, total_timeout: 2)
|
||||
response = session.get(uri)
|
||||
assert response.is_a?(HTTPX::ErrorResponse), "response should have failed (#{response.class})"
|
||||
|
@ -20,3 +20,17 @@ Dir[File.join(".", "test", "support", "**", "*.rb")].sort.each { |f| require f }
|
||||
# Ruby 2.3 openssl configuration somehow ignores SSL_CERT_FILE env var.
|
||||
# This adds it manually.
|
||||
OpenSSL::SSL::SSLContext::DEFAULT_CERT_STORE.add_file(ENV["SSL_CERT_FILE"]) if RUBY_VERSION.start_with?("2.3") && ENV.key?("SSL_CERT_FILE")
|
||||
|
||||
# 9090 drops SYN packets for connect timeout tests, make sure there's a server binding there.
|
||||
server = TCPServer.new("127.0.0.1", 9090)
|
||||
|
||||
Thread.start do
|
||||
begin
|
||||
sock = server.accept
|
||||
warn "received: #{sock}"
|
||||
sock.close
|
||||
rescue StandardError => e
|
||||
puts "smth weird happened: #{e.class} -> #{e.message}"
|
||||
puts e.backtrace
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user