Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NettyHttpServerTest.testErrorBeforeRead handle exception #1848

Merged
merged 2 commits into from
Sep 29, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -584,12 +584,6 @@ void testSingleError(ExecutorSupplier clientExecutorSupplier,
void testErrorBeforeRead(ExecutorSupplier clientExecutorSupplier,
ExecutorSupplier serverExecutorSupplier) throws Exception {
setUp(clientExecutorSupplier, serverExecutorSupplier);
// Flaky test: https://github.com/apple/servicetalk/issues/245
ignoreTestWhen(IMMEDIATE, IMMEDIATE);
ignoreTestWhen(IMMEDIATE, CACHED);
ignoreTestWhen(CACHED, IMMEDIATE);
ignoreTestWhen(CACHED, CACHED);

final StreamingHttpRequest request = reqRespFactory.newRequest(GET, SVC_ERROR_BEFORE_READ).payloadBody(
getChunkPublisherFromStrings("Goodbye", "cruel", "world!"));

Expand All @@ -601,14 +595,18 @@ void testErrorBeforeRead(ExecutorSupplier clientExecutorSupplier,

final BlockingIterator<Buffer> httpPayloadChunks = response.payloadBody().toIterable().iterator();

Exception e = assertThrows(Exception.class, () -> httpPayloadChunks.next());
Exception e = assertThrows(Exception.class, httpPayloadChunks::next);
assertThat(e, either(instanceOf(RuntimeException.class)).or(instanceOf(ExecutionException.class)));
// Due to a race condition, the exception cause here can vary.
// If the socket closure is delayed slightly
// (for example, by delaying the Publisher.error(...) on the server)
// then the client throws ClosedChannelException. However if the socket closure happens quickly enough,
// the client throws NativeIoException (KQueue) or IOException (NIO).
assertThat(e.getCause(), instanceOf(IOException.class));
} catch (Throwable cause) {
// The server intentionally triggers an error when it writes, if this happens before all content is read
// the client may fail to write the request due to premature connection closure.
assertThat(cause, instanceOf(ClosedChannelException.class));
} finally {
assertConnectionClosed();
}
Expand Down