-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Introduce ParallelExecutionInterceptor
and sample implementation
#5027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The new `junit.jupiter.execution.parallel.config.interceptor.class` configuration parameter allows configuring the fully qualified class name of a `ParallelExecutionInterceptor` implementation that gets called for each executed `TestTask`. The `FixedThreadPoolForTests` sample implementation uses a separate fixed thread pool to run all tasks of type `TEST` with execution mode `CONCURRENT` in. Resolves #3108.
While this solves the specific problem, the implementation feels incomplete. Is that intentional? When using a fixed thread pool, for each subtrees that must be executed on the same thread, I would expect that a thread from the thread pool is used for that entire subtree. With tasks of the type tests as the trivial case. Edit: wording for clarity. |
Since tests using |
I was under the impression that the |
It only does so if exclusive resource / resource locks are used. |
// If this method is called from outside the used ForkJoinPool, | ||
// calls to fork() will schedule tasks in the commonPool | ||
Preconditions.condition(isAlreadyRunningInForkJoinPool(), | ||
"invokeAll() must be called from a thread in the ForkJoinPool"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to create a dummy task that calls invokeAll
and submit
that task instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. No then SAME_THREAD
won't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But what if only the call to joinConcurrentTasksInReverseOrderToEnableWorkStealing(concurrentTasksInReverseOrder);
is submitted?
What if, upon encountering |
To clarify what I meant by incompleteness. When using Expressed as a test case: @Execution(CONCURRENT)
static class ExampleTest {
final static ThreadLocal<Integer> threadLocal = new ThreadLocal<>();
@BeforeAll
static void initialize() {
assertThat(Thread.currentThread().getName()).doesNotStartWith("ForkJoinPool");
threadLocal.set(42);
}
@Test
@Execution(SAME_THREAD)
void firstTest() throws Exception {
assertThat(Thread.currentThread().getName()).doesNotStartWith("ForkJoinPool");
assertEquals(42, threadLocal.get());
}
@Test
void secondTest() throws Exception {
assertThat(Thread.currentThread().getName()).doesNotStartWith("ForkJoinPool");
assertNull(threadLocal.get());
}
} But I haven't quite got the time to try out my suggestions in code and see if they would actually work as expected.. Apologies for that. |
The new
junit.jupiter.execution.parallel.config.interceptor.class
configuration parameter allows configuring the fully qualified class
name of a
ParallelExecutionInterceptor
implementation that gets calledfor each executed
TestTask
. TheFixedThreadPoolForTests
sampleimplementation uses a separate fixed thread pool to run all tasks of
type
TEST
with execution modeCONCURRENT
in.Resolves #3108.
I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@API
annotations