Skip to content

Commit

Permalink
CancellationTest capture stacktrace when stream is closed
Browse files Browse the repository at this point in the history
(cherry picked from commit bb54b62)
  • Loading branch information
tkountis committed Mar 4, 2021
1 parent c7ef401 commit 60ee945
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public Set<Object> getSingletons() {
}

@Test
public void cancelSuspended() throws Exception {
public void cancelSuspended() throws Throwable {
final TestCancellable cancellable = new TestCancellable();
when(execMock.schedule(any(Runnable.class), eq(7L), eq(DAYS))).thenReturn(cancellable);

Expand All @@ -144,24 +144,24 @@ public void cancelSuspended() throws Exception {
}

@Test
public void cancelSingle() throws Exception {
public void cancelSingle() throws Throwable {
testCancelResponseSingle(get("/single"));
}

@Test
public void cancelOffload() throws Exception {
public void cancelOffload() throws Throwable {
testCancelResponseSingle(get("/offload"));
}

@Test
public void cancelOioStreams() throws Exception {
public void cancelOioStreams() throws Throwable {
testCancelResponsePayload(post("/oio-streams"));
testCancelResponseSingle(post("/offload-oio-streams"));
testCancelResponseSingle(post("/no-offloads-oio-streams"));
}

@Test
public void cancelRsStreams() throws Exception {
public void cancelRsStreams() throws Throwable {
testCancelResponsePayload(post("/rs-streams"));
testCancelResponsePayload(post("/rs-streams?subscribe=true"));
testCancelResponseSingle(post("/offload-rs-streams"));
Expand All @@ -171,7 +171,7 @@ public void cancelRsStreams() throws Exception {
}

@Test
public void cancelSse() throws Exception {
public void cancelSse() throws Throwable {
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
return execRule.executor().schedule((Runnable) args[0], (long) args[1], (TimeUnit) args[2]);
Expand All @@ -184,7 +184,7 @@ public void cancelSse() throws Exception {
cancellableResources.sseSinkClosedLatch.await();
}

private void testCancelResponsePayload(final StreamingHttpRequest req) throws Exception {
private void testCancelResponsePayload(final StreamingHttpRequest req) throws Throwable {
// The handler method uses OutputStream APIs which are blocking. So we need to call handle and subscribe on
// different threads because the write operation will block on the Subscriber creating requestN demand.
Single<StreamingHttpResponse> respSingle = execRule.executor().submit(() ->
Expand All @@ -206,15 +206,17 @@ private void testCancelResponsePayload(final StreamingHttpRequest req) throws Ex

cancelledLatch.await();

assertThat(errorRef.get(), is(nullValue()));
if (errorRef.get() != null) {
throw errorRef.get();
}
}

private void testCancelResponseSingle(final StreamingHttpRequest req) throws Exception {
private void testCancelResponseSingle(final StreamingHttpRequest req) throws Throwable {
testCancelResponseSingle(req, true);
}

private void testCancelResponseSingle(final StreamingHttpRequest req,
boolean enableOffload) throws Exception {
boolean enableOffload) throws Throwable {
final AtomicReference<Throwable> errorRef = new AtomicReference<>();
final CountDownLatch cancelledLatch = new CountDownLatch(1);

Expand Down Expand Up @@ -258,7 +260,9 @@ public void onError(final Throwable t) {

cancelledLatch.await();

assertThat(errorRef.get(), is(nullValue()));
if (errorRef.get() != null) {
throw errorRef.get();
}
}

private static StreamingHttpRequest get(final String resourcePath) {
Expand Down

0 comments on commit 60ee945

Please sign in to comment.