diff --git a/test/session_test.rb b/test/session_test.rb index ce9005c3..6004d27f 100644 --- a/test/session_test.rb +++ b/test/session_test.rb @@ -58,7 +58,7 @@ class SessionTest < Minitest::Test end def test_session_timeout_connect_timeout - uri = build_uri("/", origin("127.0.0.1:9090")) + uri = build_uri("/", origin("127.0.0.1:#{CONNECT_TIMEOUT_PORT}")) 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})" diff --git a/test/support/ci/build.sh b/test/support/ci/build.sh index fbcc8e1b..6f8ddcd1 100755 --- a/test/support/ci/build.sh +++ b/test/support/ci/build.sh @@ -11,8 +11,10 @@ else fi # use port 9090 to test connection timeouts -iptables -A OUTPUT -p tcp -m tcp --tcp-flags SYN SYN --sport 9090 -j DROP +CONNECT_TIMEOUT_PORT=9090 +iptables -A OUTPUT -p tcp -m tcp --tcp-flags SYN SYN --sport $CONNECT_TIMEOUT_PORT -j DROP +export CONNECT_TIMEOUT_PORT=$CONNECT_TIMEOUT_PORT 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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 53cabf3c..bc96ce8d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -22,7 +22,9 @@ Dir[File.join(".", "test", "support", "**", "*.rb")].sort.each { |f| require f } 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) +CONNECT_TIMEOUT_PORT = ENV.fetch("CONNECT_TIMEOUT_PORT", 9090).to_i + +server = TCPServer.new("127.0.0.1", CONNECT_TIMEOUT_PORT) Thread.start do begin