async-http-client icon indicating copy to clipboard operation
async-http-client copied to clipboard

Allow immediate request failure on connection error

Open dnadoba opened this issue 3 years ago • 0 comments

Motivation

In integration tests we often want to inspect the connection error thrown during connection establishment for a request. Currently the only way to get at the connection error is to wait until the request timeout is expired. This is because of the connection retry behaviour backed into AHC which cannot be turned off. AHC will try to create new connections on connection failure with an exponential backoff. It stores the last connection and will fail the request if the request times out.

Modification

Adds a new internal flag called retryConnectionEstablishment to HTTPClient.Configuration.ConnectionPool. If false, requests will fail immediately after a connection could not be established. Otherwise the old behavior is used which is still the default.

Set retryConnectionEstablishment to false to speedup test from ~40s to ~1s in HTTPClientNIOTSTests.swift. More tests will follow.

Result

Allows fast and reliable test execution.

dnadoba avatar Sep 06 '22 14:09 dnadoba