Skip to content

Commit

Permalink
Fix flaky test ContextCancellationTest (#5869)
Browse files Browse the repository at this point in the history
Motivation:

Let me just remove the validation like @minwoox suggested

Modifications:

- Removed the validation on request context.

Result:

- #5868

<!--
Visit this URL to learn more about how to write a pull request
description:

https://armeria.dev/community/developer-guide#how-to-write-pull-request-description
-->
  • Loading branch information
jrhee17 authored Aug 12, 2024
1 parent b68665b commit 4f17989
Showing 1 changed file with 3 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,11 @@
import com.linecorp.armeria.common.HttpObject;
import com.linecorp.armeria.common.HttpRequest;
import com.linecorp.armeria.common.HttpResponse;
import com.linecorp.armeria.common.RequestContext;
import com.linecorp.armeria.common.RequestHeaders;
import com.linecorp.armeria.common.SessionProtocol;
import com.linecorp.armeria.common.annotation.Nullable;
import com.linecorp.armeria.common.logging.RequestLogAccess;
import com.linecorp.armeria.common.stream.SubscriptionOption;
import com.linecorp.armeria.common.util.SafeCloseable;
import com.linecorp.armeria.internal.common.RequestContextUtil;
import com.linecorp.armeria.internal.testing.MockAddressResolverGroup;
import com.linecorp.armeria.server.ServerBuilder;
import com.linecorp.armeria.testing.junit5.common.EventLoopGroupExtension;
Expand All @@ -62,7 +59,6 @@ class ContextCancellationTest {

private static final Set<String> requests = Sets.newConcurrentHashSet();
private static final BlockingQueue<Thread> callbackThreads = new LinkedBlockingQueue<>();
private static final Set<RequestContext> callbackContexts = Sets.newConcurrentHashSet();
private static final String eventLoopThreadPrefix = "context-cancellation-test";
private static final String HEADER = "x-request-id";

Expand All @@ -84,7 +80,6 @@ protected void configure(ServerBuilder sb) throws Exception {
void beforeEach() {
requests.clear();
callbackThreads.clear();
callbackContexts.clear();
}

@Test
Expand Down Expand Up @@ -246,15 +241,14 @@ void cancel_beforeWriteFinished(TestInfo testInfo) {
@Override
public void subscribe(Subscriber<? super HttpObject> subscriber, EventExecutor executor,
SubscriptionOption... options) {
ctxRef.get().cancel(t);
super.subscribe(subscriber, executor, options);
try (SafeCloseable ignored = RequestContextUtil.pop()) {
ctxRef.get().cancel(t);
}
}
});
assertThatThrownBy(() -> res.aggregate().join())
.isInstanceOf(CompletionException.class)
.hasCause(t);
.hasCauseInstanceOf(UnprocessedRequestException.class)
.hasRootCause(t);
assertThat(connListener.opened()).isEqualTo(1);
validateCallbackChecks(eventLoopThreadPrefix);
}
Expand Down Expand Up @@ -286,7 +280,6 @@ void cancel_waitingForResponse(TestInfo testInfo) {
}

static void validateCallbackChecks(@Nullable String expectedPrefix) {
assertThat(callbackContexts).isEmpty();
if (expectedPrefix != null) {
assertThat(callbackThreads).allSatisfy(t -> assertThat(t.getName()).startsWith(expectedPrefix));
}
Expand Down Expand Up @@ -338,10 +331,6 @@ public HttpResponse execute(ClientRequestContext ctx, HttpRequest req) throws Ex
private static void attachCallbackChecks(RequestLogAccess log) {
final Runnable runnable = () -> {
callbackThreads.add(Thread.currentThread());
final RequestContext ctx = RequestContext.currentOrNull();
if (ctx != null) {
callbackContexts.add(ctx);
}
};
log.whenRequestComplete().thenRun(runnable);
log.whenComplete().thenRun(runnable);
Expand Down

0 comments on commit 4f17989

Please sign in to comment.