|
24 | 24 | import org.apache.http.impl.nio.client.HttpAsyncClients; |
25 | 25 | import org.apache.http.message.BasicHeader; |
26 | 26 | import org.apache.http.nio.client.HttpAsyncClient; |
27 | | -import org.junit.jupiter.api.BeforeAll; |
| 27 | +import org.junit.jupiter.api.BeforeEach; |
28 | 28 | import org.junit.jupiter.api.Nested; |
29 | | -import org.junit.jupiter.api.TestInstance; |
30 | 29 | import org.junit.jupiter.api.extension.RegisterExtension; |
31 | 30 |
|
32 | | -@TestInstance(TestInstance.Lifecycle.PER_CLASS) |
33 | 31 | class ApacheHttpAsyncClientTest { |
34 | 32 |
|
35 | 33 | @RegisterExtension |
36 | 34 | static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forAgent(); |
37 | 35 |
|
38 | 36 | @RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create(); |
39 | 37 |
|
40 | | - private final RequestConfig requestConfig = |
| 38 | + private static final RequestConfig requestConfig = |
41 | 39 | RequestConfig.custom() |
42 | 40 | .setConnectTimeout((int) AbstractHttpClientTest.CONNECTION_TIMEOUT.toMillis()) |
43 | 41 | .build(); |
44 | 42 |
|
45 | | - private final RequestConfig requestWithReadTimeoutConfig = |
| 43 | + private static final RequestConfig requestWithReadTimeoutConfig = |
46 | 44 | RequestConfig.copy(requestConfig) |
47 | 45 | .setSocketTimeout((int) AbstractHttpClientTest.READ_TIMEOUT.toMillis()) |
48 | 46 | .build(); |
49 | 47 |
|
50 | | - private final CloseableHttpAsyncClient client = |
51 | | - HttpAsyncClients.custom().setDefaultRequestConfig(requestConfig).build(); |
52 | | - private final CloseableHttpAsyncClient clientWithReadTimeout = |
53 | | - HttpAsyncClients.custom().setDefaultRequestConfig(requestWithReadTimeoutConfig).build(); |
| 48 | + private CloseableHttpAsyncClient client; |
| 49 | + private CloseableHttpAsyncClient clientWithReadTimeout; |
54 | 50 |
|
55 | | - @BeforeAll |
| 51 | + // Use a fresh client per test: with httpasyncclient 4.1.5 a failing test can leave the |
| 52 | + // shared I/O reactor in a STOPPED state, cascading "Request execution cancelled" failures |
| 53 | + // into every subsequent test. |
| 54 | + @BeforeEach |
56 | 55 | void setUp() { |
57 | | - cleanup.deferAfterAll(client); |
58 | | - cleanup.deferAfterAll(clientWithReadTimeout); |
| 56 | + client = HttpAsyncClients.custom().setDefaultRequestConfig(requestConfig).build(); |
| 57 | + clientWithReadTimeout = |
| 58 | + HttpAsyncClients.custom().setDefaultRequestConfig(requestWithReadTimeoutConfig).build(); |
| 59 | + cleanup.deferCleanup(client); |
| 60 | + cleanup.deferCleanup(clientWithReadTimeout); |
59 | 61 | client.start(); |
60 | 62 | clientWithReadTimeout.start(); |
61 | 63 | } |
|
0 commit comments