Skip to content

Commit

Permalink
Improvements for ConnectionCloseHeaderHandlingTest (#3099)
Browse files Browse the repository at this point in the history
Motivation:

1. `serverCloseSecondPipelinedRequestWriteAborted` test should write
only portion of the `/second` request to simulate incomplete write.
Currently, it writes the full content and then concats with `never()`.
As a result, internal state machine of the pipelined connection
(`RequestResponseCloseHandler`) thinks that we already finished the
write.
2. `tearDown()` may throw NPE if we use `assume` to skip some test
scenarios.

Modifications:

1. Write only half of the intended content.
2. Add null checks inside `tearDown()` method.
  • Loading branch information
idelpivnitskiy authored Nov 13, 2024
1 parent 9fb0d0d commit 0955acb
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.servicetalk.buffer.api.Buffer;
import io.servicetalk.concurrent.BlockingIterator;
import io.servicetalk.concurrent.api.Completable;
import io.servicetalk.concurrent.api.CompositeCloseable;
import io.servicetalk.http.api.HttpPayloadWriter;
import io.servicetalk.http.api.HttpServerBuilder;
import io.servicetalk.http.api.ReservedStreamingHttpConnection;
Expand Down Expand Up @@ -132,7 +133,7 @@ void setUp(boolean useUds, boolean viaProxy, boolean awaitRequestPayload) throws
HttpServers.forAddress(localAddress(0)))
.ioExecutor(serverCtx.ioExecutor())
.executor(serverCtx.executor())
.enableWireLogging("servicetalk-tests-wire-logger", TRACE, Boolean.TRUE::booleanValue)
.enableWireLogging("servicetalk-tests-wire-logger", TRACE, () -> true)
.appendConnectionAcceptorFilter(original -> new DelegatingConnectionAcceptor(original) {
@Override
public Completable accept(final ConnectionContext context) {
Expand Down Expand Up @@ -216,7 +217,17 @@ public Completable accept(final ConnectionContext context) {
@AfterEach
void tearDown() throws Exception {
try {
newCompositeCloseable().appendAll(connection, client, serverContext).close();
CompositeCloseable closeable = newCompositeCloseable();
if (connection != null) {
closeable.append(connection);
}
if (client != null) {
closeable.append(client);
}
if (serverContext != null) {
closeable.append(serverContext);
}
closeable.close();
} finally {
if (proxyTunnel != null) {
safeClose(proxyTunnel);
Expand Down Expand Up @@ -392,7 +403,9 @@ void serverCloseSecondPipelinedRequestWriteAborted(boolean useUds, boolean viaPr
String content = "request_content";
connection.request(connection.get("/second")
.addHeader(CONTENT_LENGTH, valueOf(content.length()))
.payloadBody(from(content).concat(never()), RAW_STRING_SERIALIZER))
// Write only part of the intended payload body to simulate incomplete request:
.payloadBody(from(content.substring(0, content.length() / 2)).concat(never()),
RAW_STRING_SERIALIZER))
.whenOnError(secondRequestError::set)
.whenFinally(secondResponseReceived::countDown)
.subscribe(second -> { });
Expand Down

0 comments on commit 0955acb

Please sign in to comment.