Skip to content

Commit af01383

Browse files
http-netty: Re-enable ClientEfectivenessStrategyTest.clientStrategy (#3105)
Motivation: We had previously disabled the clientStrategy test because it's flaky. According to the notes in the issue (#2245) it is only in one part, and that is in the Send stage which appears to be offloaded when it shouldn't be. Modifications: Re-enable the test and prune those errors, and log them.
1 parent 799574e commit af01383

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/ClientEffectiveStrategyTest.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,21 @@
5656
import org.hamcrest.Matchers;
5757
import org.junit.jupiter.api.AfterAll;
5858
import org.junit.jupiter.api.BeforeAll;
59-
import org.junit.jupiter.api.Disabled;
6059
import org.junit.jupiter.api.extension.RegisterExtension;
6160
import org.junit.jupiter.api.parallel.Execution;
6261
import org.junit.jupiter.api.parallel.ExecutionMode;
6362
import org.junit.jupiter.params.ParameterizedTest;
6463
import org.junit.jupiter.params.provider.Arguments;
6564
import org.junit.jupiter.params.provider.MethodSource;
65+
import org.junit.platform.commons.logging.Logger;
66+
import org.junit.platform.commons.logging.LoggerFactory;
6667

6768
import java.net.InetSocketAddress;
6869
import java.util.ArrayList;
6970
import java.util.Collection;
7071
import java.util.Collections;
7172
import java.util.EnumSet;
73+
import java.util.Iterator;
7274
import java.util.List;
7375
import java.util.Objects;
7476
import java.util.Queue;
@@ -102,6 +104,8 @@
102104
@Execution(ExecutionMode.SAME_THREAD)
103105
class ClientEffectiveStrategyTest {
104106

107+
private static final Logger LOGGER = LoggerFactory.getLogger(ClientEffectiveStrategyTest.class);
108+
105109
@RegisterExtension
106110
static final ExecutionContextExtension SERVER_CTX =
107111
ExecutionContextExtension.cached("server-io", "server-executor")
@@ -228,7 +232,6 @@ static Stream<Arguments> casesSupplier() {
228232
return arguments.stream();
229233
}
230234

231-
@Disabled // Disabled due to continued flakiness. See issue #2245 for more details.
232235
@ParameterizedTest(name = "Type={0} builder={1} filter={2} LB={3} CF={4}")
233236
@MethodSource("casesSupplier")
234237
void clientStrategy(final BuilderType builderType,
@@ -330,7 +333,7 @@ public HttpExecutionStrategy requiredOffloads() {
330333
invokingThreadsRecorder.reset(effectiveStrategy);
331334
String responseBody = getResponse(clientApi, client, requestTarget);
332335
assertThat("Unexpected response: " + responseBody, responseBody, is(not(emptyString())));
333-
invokingThreadsRecorder.verifyOffloads(clientApi, client.executionContext().executionStrategy(),
336+
invokingThreadsRecorder.flakyVerifyOffloads(clientApi, client.executionContext().executionStrategy(),
334337
responseBody);
335338

336339
// Execute request one more time to make sure we cover all paths:
@@ -339,7 +342,7 @@ public HttpExecutionStrategy requiredOffloads() {
339342
invokingThreadsRecorder.reset(effectiveStrategy);
340343
responseBody = getResponse(clientApi, client, requestTarget);
341344
assertThat("Unexpected response: " + responseBody, responseBody, is(not(emptyString())));
342-
invokingThreadsRecorder.verifyOffloads(clientApi, client.executionContext().executionStrategy(),
345+
invokingThreadsRecorder.flakyVerifyOffloads(clientApi, client.executionContext().executionStrategy(),
343346
responseBody);
344347
}
345348
}
@@ -564,6 +567,31 @@ void recordThread(final ClientOffloadPoint offloadPoint, final HttpExecutionStra
564567
});
565568
}
566569

570+
void flakyVerifyOffloads(ClientApi clientApi, HttpExecutionStrategy clientStrategy, String apiStrategy) {
571+
// For flaky tests we see unexpected offloading at the Send stage. This is messing with CI so this
572+
// particular test case is skipped for now.
573+
// See https://github.com/apple/servicetalk/issues/2245
574+
Throwable firstFlakyException = null;
575+
Iterator<Throwable> it = errors.iterator();
576+
while (it.hasNext()) {
577+
Throwable t = it.next();
578+
// Example message:
579+
// Suppressed: java.lang.AssertionError: Expected IoThread or ForkJoinPool-1-worker-1
580+
// at Send, but was running on an offloading executor thread: client-executor-7-5.
581+
// clientStrategy=DEFAULT_HTTP_EXECUTION_STRATEGY, expectedStrategy=OFFLOAD_NONE_STRATEGY,
582+
// requestStrategy=DEFAULT_HTTP_EXECUTION_STRATEGY"
583+
if (clientApi == ClientApi.BLOCKING_AGGREGATED && t.getMessage().contains(
584+
"but was running on an offloading executor thread")) {
585+
firstFlakyException = firstFlakyException == null ? t : firstFlakyException;
586+
it.remove();
587+
}
588+
}
589+
if (firstFlakyException != null) {
590+
LOGGER.warn(firstFlakyException, () -> "Flaky throwable detected. Ignoring until test can be fixed.");
591+
}
592+
verifyOffloads(clientApi, clientStrategy, apiStrategy);
593+
}
594+
567595
public void verifyOffloads(ClientApi clientApi, HttpExecutionStrategy clientStrategy, String apiStrategy) {
568596
assertNoAsyncErrors("API=" + clientApi + ", apiStrategy=" + apiStrategy +
569597
", clientStrategy=" + clientStrategy +

0 commit comments

Comments
 (0)