-
Type: Improvement
-
Status: Resolved
-
Priority: Minor
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 9.3
-
Release Notes Description:
-
Tags:
-
Impact type:API change
-
Upgrade notes:
-
Sprint:nxfit 9.3.2
-
Story Points:8
The BaseTest class initializes a Jersey client with Client#create(ClientConfig cc) that uses the default URLConnectionClientHandler that relies on java.net.HttpURLConnection, the JDK's HTTP client.
The JDK's Keep-Alive strategy (see http://docs.oracle.com/javase/8/docs/technotes/guides/net/http-keepalive.html) isn't suitable for our unit tests relying on the JettyFeature: a TCP connection opened within a test class (A) can be reused to send HTTP requests in the next executed test class (B), yet when the JettyComponent stops between the 2 test classes it closes the connection's underlying socket.
In this case, the TCP FIN flag is sent to the client. When the first request of B's first test is sent, the server responds with the TCP RST flag (reset) because the connection has been closed, leading to an empty HTTP response thus a failure when trying to get parsed.
This was detected when investigating NXP-22781: the BatchUploadFixture suite class is run twice in a row by BatchUploadTest and RedisBatchUploadTest. The second run would fail because trying to reuse a connection kept alive from the first run.
Notes:
- This could possibly happen with 2 consecutive test classes not running the same suite class. It's not clear why it was only detected in this case, maybe because the Keep-Alive timeout is 5 seconds (arbitrary and non-configurable value used by the JDK) and is usually is short enough to expire between 2 test class runs.
- This is happening since
NXP-18317. Before that, the first POST request of B's first test would be retried in case of failure, opening a new connection thus succeeding. Now that we don't retry a failing POST request, a java.net.SocketException: Unexpected end of file from server is thrown.
The ApacheHttpClient4Handler is also much more configurable than the default one through the org.apache.http.impl.client.HttpClientBuilder API.