Skip to content

Commit

Permalink
Fix flaky publisher/OffloadingTest (#2751)
Browse files Browse the repository at this point in the history
Motivation:

#2325 says that test failures are caused by
"Executor was not initialized" or `RejectedExecutionException`.
This is the only test that uses `ExecutionMode.CONCURRENT` and
`ExecutorExtension` for `APP_EXECUTOR_EXT` is not marked as class-level.

Modifications:

- Remove `ExecutionMode.CONCURRENT` from publisher/OffloadingTest;
- Use `setClassLevel` for all static `APP_EXECUTOR_EXT` in
`AbstractOffloadingTest`;
- Adjust names of `ParameterizedTest`(s);

Result:

Resolves #2325.
  • Loading branch information
idelpivnitskiy authored Nov 11, 2023
1 parent 25b09db commit 414601f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ enum OffloadCase {
}
}

@ParameterizedTest
@EnumSource(OffloadingTest.OffloadCase.class)
@ParameterizedTest(name = "{displayName} [{index}]: case={0}")
@EnumSource(OffloadCase.class)
void testOffloading(OffloadCase offloadCase) throws InterruptedException {
int offloads = testOffloading(offloadCase.offloadOperator, offloadCase.terminal);
assertThat("Unexpected offloads: " + offloadCase.expectedOffloads,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.servicetalk.concurrent.api.AsyncContext;
import io.servicetalk.concurrent.api.Executor;
import io.servicetalk.concurrent.api.ExecutorExtension;
import io.servicetalk.concurrent.api.Executors;
import io.servicetalk.concurrent.api.TestExecutor;
import io.servicetalk.concurrent.internal.DeliberateException;
import io.servicetalk.context.api.ContextMap;
Expand All @@ -28,7 +29,6 @@
import org.slf4j.LoggerFactory;

import static io.servicetalk.concurrent.api.ExecutorExtension.withCachedExecutor;
import static io.servicetalk.concurrent.api.Executors.immediate;
import static io.servicetalk.context.api.ContextMap.Key.newKey;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.startsWith;
Expand Down Expand Up @@ -80,9 +80,10 @@ protected enum TerminalOperation {
protected static final Matcher<String> OFFLOAD_EXECUTOR = startsWith("TestExecutor");

@RegisterExtension
public static final ExecutorExtension<Executor> APP_EXECUTOR_EXT = APP_ISOLATION ?
public static final ExecutorExtension<Executor> APP_EXECUTOR_EXT = (APP_ISOLATION ?
withCachedExecutor(APP_EXECUTOR_PREFIX) :
ExecutorExtension.withExecutor(() -> immediate()).setClassLevel(true);
ExecutorExtension.withExecutor(Executors::immediate))
.setClassLevel(true);
@RegisterExtension
public final ExecutorExtension<TestExecutor> testExecutor = ExecutorExtension.withTestExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

import org.hamcrest.CoreMatchers;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

Expand Down Expand Up @@ -50,7 +48,6 @@
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;

@Execution(ExecutionMode.CONCURRENT)
class OffloadingTest extends AbstractPublisherOffloadingTest {

enum OffloadCase {
Expand Down Expand Up @@ -190,7 +187,7 @@ enum OffloadCase {
}
}

@ParameterizedTest
@ParameterizedTest(name = "{displayName} [{index}]: case={0}")
@EnumSource(OffloadCase.class)
void testOffloading(OffloadCase offloadCase) throws InterruptedException {
int offloads = testOffloading(offloadCase.offloadOperator, offloadCase.terminal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ enum OffloadCase {
}
}

@ParameterizedTest
@EnumSource(OffloadingTest.OffloadCase.class)
void testOffloading(OffloadingTest.OffloadCase offloadCase) throws InterruptedException {
@ParameterizedTest(name = "{displayName} [{index}]: case={0}")
@EnumSource(OffloadCase.class)
void testOffloading(OffloadCase offloadCase) throws InterruptedException {
int offloads = testOffloading(offloadCase.offloadOperator, offloadCase.terminal);
assertThat("Unexpected offloads: " + offloadCase.expectedOffloads,
offloads, CoreMatchers.is(offloadCase.offloadsExpected));
Expand Down

0 comments on commit 414601f

Please sign in to comment.