Skip to content

Commit

Permalink
rewrite test as suggested
Browse files Browse the repository at this point in the history
  • Loading branch information
ywangd committed Oct 10, 2024
1 parent ffaefbd commit e90005d
Showing 1 changed file with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,24 +177,27 @@ public void testInternalSendExceptionForksToGenericIfHandlerDoesNotForkAndStackO
);
}

public void testInternalSendExceptionWithNonForkingResponseHandlerCanCompleteFutureWaiterFromGenericThread() throws Exception {
public void testInternalSendExceptionWithNonForkingResponseHandlerCompletesListenerInline() {
try (var nodeA = new TestNode("node-A")) {
final var future = new PlainActionFuture<TransportResponse.Empty>();
nodeA.transportService.getThreadPool().generic().execute(() -> {
assertEquals("simulated exception in sendRequest", getSendRequestException(future, IOException.class).getMessage());
});
final Thread callingThread = Thread.currentThread();
nodeA.transportService.sendRequest(
nodeA.getThrowingConnection(),
TestNode.randomActionName(random()),
new EmptyRequest(),
TransportRequestOptions.EMPTY,
new ActionListenerResponseHandler<>(future.delegateResponse((l, e) -> {
assertThat(Thread.currentThread(), is(callingThread));
l.onFailure(e);
}), unusedReader(), EsExecutors.DIRECT_EXECUTOR_SERVICE)
assertEquals(
"simulated exception in sendRequest",
safeAwaitAndUnwrapFailure(
IOException.class,
TransportResponse.Empty.class,
l -> nodeA.transportService.sendRequest(
nodeA.getThrowingConnection(),
TestNode.randomActionName(random()),
new EmptyRequest(),
TransportRequestOptions.EMPTY,
new ActionListenerResponseHandler<>(
ActionListener.runBefore(l, () -> assertSame(callingThread, Thread.currentThread())),
unusedReader(),
EsExecutors.DIRECT_EXECUTOR_SERVICE
)
)
).getMessage()
);
assertBusy(() -> assertTrue(future.isDone()));
}
}

Expand Down

0 comments on commit e90005d

Please sign in to comment.