56
56
import org .hamcrest .Matchers ;
57
57
import org .junit .jupiter .api .AfterAll ;
58
58
import org .junit .jupiter .api .BeforeAll ;
59
- import org .junit .jupiter .api .Disabled ;
60
59
import org .junit .jupiter .api .extension .RegisterExtension ;
61
60
import org .junit .jupiter .api .parallel .Execution ;
62
61
import org .junit .jupiter .api .parallel .ExecutionMode ;
63
62
import org .junit .jupiter .params .ParameterizedTest ;
64
63
import org .junit .jupiter .params .provider .Arguments ;
65
64
import org .junit .jupiter .params .provider .MethodSource ;
65
+ import org .junit .platform .commons .logging .Logger ;
66
+ import org .junit .platform .commons .logging .LoggerFactory ;
66
67
67
68
import java .net .InetSocketAddress ;
68
69
import java .util .ArrayList ;
69
70
import java .util .Collection ;
70
71
import java .util .Collections ;
71
72
import java .util .EnumSet ;
73
+ import java .util .Iterator ;
72
74
import java .util .List ;
73
75
import java .util .Objects ;
74
76
import java .util .Queue ;
102
104
@ Execution (ExecutionMode .SAME_THREAD )
103
105
class ClientEffectiveStrategyTest {
104
106
107
+ private static final Logger LOGGER = LoggerFactory .getLogger (ClientEffectiveStrategyTest .class );
108
+
105
109
@ RegisterExtension
106
110
static final ExecutionContextExtension SERVER_CTX =
107
111
ExecutionContextExtension .cached ("server-io" , "server-executor" )
@@ -228,7 +232,6 @@ static Stream<Arguments> casesSupplier() {
228
232
return arguments .stream ();
229
233
}
230
234
231
- @ Disabled // Disabled due to continued flakiness. See issue #2245 for more details.
232
235
@ ParameterizedTest (name = "Type={0} builder={1} filter={2} LB={3} CF={4}" )
233
236
@ MethodSource ("casesSupplier" )
234
237
void clientStrategy (final BuilderType builderType ,
@@ -330,7 +333,7 @@ public HttpExecutionStrategy requiredOffloads() {
330
333
invokingThreadsRecorder .reset (effectiveStrategy );
331
334
String responseBody = getResponse (clientApi , client , requestTarget );
332
335
assertThat ("Unexpected response: " + responseBody , responseBody , is (not (emptyString ())));
333
- invokingThreadsRecorder .verifyOffloads (clientApi , client .executionContext ().executionStrategy (),
336
+ invokingThreadsRecorder .flakyVerifyOffloads (clientApi , client .executionContext ().executionStrategy (),
334
337
responseBody );
335
338
336
339
// Execute request one more time to make sure we cover all paths:
@@ -339,7 +342,7 @@ public HttpExecutionStrategy requiredOffloads() {
339
342
invokingThreadsRecorder .reset (effectiveStrategy );
340
343
responseBody = getResponse (clientApi , client , requestTarget );
341
344
assertThat ("Unexpected response: " + responseBody , responseBody , is (not (emptyString ())));
342
- invokingThreadsRecorder .verifyOffloads (clientApi , client .executionContext ().executionStrategy (),
345
+ invokingThreadsRecorder .flakyVerifyOffloads (clientApi , client .executionContext ().executionStrategy (),
343
346
responseBody );
344
347
}
345
348
}
@@ -564,6 +567,31 @@ void recordThread(final ClientOffloadPoint offloadPoint, final HttpExecutionStra
564
567
});
565
568
}
566
569
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
+
567
595
public void verifyOffloads (ClientApi clientApi , HttpExecutionStrategy clientStrategy , String apiStrategy ) {
568
596
assertNoAsyncErrors ("API=" + clientApi + ", apiStrategy=" + apiStrategy +
569
597
", clientStrategy=" + clientStrategy +
0 commit comments