-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Support some level of parallelization in junit-vintage-engine #4135
base: main
Are you sure you want to change the base?
Support some level of parallelization in junit-vintage-engine #4135
Conversation
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.
Thanks for submitting the draft! I left a bunch of comments. 🙂
junit-vintage-engine/src/main/java/org/junit/vintage/engine/VintageTestEngine.java
Outdated
Show resolved
Hide resolved
junit-vintage-engine/src/main/java/org/junit/vintage/engine/VintageTestEngine.java
Outdated
Show resolved
Hide resolved
junit-vintage-engine/src/main/java/org/junit/vintage/engine/VintageTestEngine.java
Outdated
Show resolved
Hide resolved
junit-vintage-engine/src/main/java/org/junit/vintage/engine/VintageTestEngine.java
Outdated
Show resolved
Hide resolved
junit-vintage-engine/src/main/java/org/junit/vintage/engine/VintageTestEngine.java
Outdated
Show resolved
Hide resolved
junit-vintage-engine/src/main/java/org/junit/vintage/engine/VintageTestEngine.java
Show resolved
Hide resolved
junit-vintage-engine/src/main/java/org/junit/vintage/engine/VintageTestEngine.java
Outdated
Show resolved
Hide resolved
Signed-off-by: yongjunhong <kevin0928@naver.com>
c25db8c
to
e12b155
Compare
junit-vintage-engine/src/main/java/org/junit/vintage/engine/VintageTestEngine.java
Outdated
Show resolved
Hide resolved
Issue: junit-team#3717 Signed-off-by: yongjunhong <kevin0928@naver.com>
If the parallelization work is completed, I would appreciate it if you could take a look at the Open Question in the PR description 😀 |
@YongGoose The last two weeks were very busy. I should be able to get to your PRs early next week, though. Cheers! |
I think it should be similar to the configuration parameters in Jupiter. Thus, I'd suggest we use |
junit-vintage-engine/src/main/java/org/junit/vintage/engine/VintageTestEngine.java
Outdated
Show resolved
Hide resolved
junit-vintage-engine/src/main/java/org/junit/vintage/engine/VintageTestEngine.java
Show resolved
Hide resolved
Issue: junit-team#2229 Signed-off-by: yongjunhong <kevin0928@naver.com>
Issue: junit-team#2229 Signed-off-by: yongjunhong <kevin0928@naver.com>
That's a great idea! I made this change in e0312cc |
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.
As a next step, could you please add some tests?
junit-vintage-engine/src/main/java/org/junit/vintage/engine/VintageTestEngine.java
Outdated
Show resolved
Hide resolved
junit-vintage-engine/src/main/java/org/junit/vintage/engine/VintageTestEngine.java
Outdated
Show resolved
Hide resolved
…ntageTestEngine.java Co-authored-by: Marc Philipp <mail@marcphilipp.de>
Issue: junit-team#2229 Signed-off-by: yongjunhong <kevin0928@naver.com>
@marcphilipp In this test case, the return value of
private boolean executeInParallel(VintageEngineDescriptor engineDescriptor,
EngineExecutionListener engineExecutionListener, ExecutionRequest request) {
ExecutorService executorService = Executors.newFixedThreadPool(getThreadPoolSize(request));
RunnerExecutor runnerExecutor = new RunnerExecutor(engineExecutionListener);
List<CompletableFuture<Void>> futures = new ArrayList<>();
for (Iterator<TestDescriptor> iterator = engineDescriptor.getModifiableChildren().iterator(); iterator.hasNext();) {
TestDescriptor descriptor = iterator.next();
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
runnerExecutor.execute((RunnerTestDescriptor) descriptor);
}, executorService);
futures.add(future);
iterator.remove();
}
@Test
void successfulParallelTest(TestReporter reporter) {
var events = executeInParallelSuccessfully(3, SuccessfulParallelTestCase.class).list();
var startedTimestamps = getTimestampsFor(events, event(test(), started()));
var finishedTimestamps = getTimestampsFor(events, event(test(), finishedSuccessfully()));
reporter.publishEntry("startedTimestamps", startedTimestamps.toString());
reporter.publishEntry("finishedTimestamps", finishedTimestamps.toString());
assertThat(startedTimestamps).hasSize(3);
assertThat(finishedTimestamps).hasSize(3);
}
@RunWith(Enclosed.class)
public class JUnit4ParallelTestCase {
public static class SuccessfulParallelTestCase {
static AtomicInteger sharedResource;
static CountDownLatch countDownLatch;
@BeforeClass
public static void initialize() {
sharedResource = new AtomicInteger();
countDownLatch = new CountDownLatch(3);
}
@Test
public void firstTest() throws Exception {
incrementAndBlock(sharedResource, countDownLatch);
}
@Test
public void secondTest() throws Exception {
incrementAndBlock(sharedResource, countDownLatch);
}
@Test
public void thirdTest() throws Exception {
incrementAndBlock(sharedResource, countDownLatch);
}
}
... Question
I believe the commit will make it easier to understand. 1484347 While implementing recursion, I noticed something unusual. When fetching If that’s the case, it seems unavoidable to modify the internal code to implement parallel execution of Alternatively, we could proceed with the current approach instead of |
de8fbce
to
1484347
Compare
Do you mean that running the children of a JUnit 4 actually has a feature that allows running methods in parallel. It works for all subclasses of |
Exactly!
I'll work on it in the next PR along with the issue once this PR is complete!
I was actually considering this issue, so thank you for the detailed suggestion!👍🏻 |
Issue: junit-team#2229 Signed-off-by: yongjunhong <kevin0928@naver.com>
1484347
to
b196388
Compare
I implemented it by extracting and comparing thread names when executing test classes. b196388 I understand that in
|
Thanks! I don't think we can reuse that here since we have to use JUnit 3/4 primitives and can't use Jupiter extensions. I'll be out for about a week for Christmas but will suggest something when I'm back. |
Have a good Christmas :) |
Overview
Resolves #2229
This PR implements parallel execution support for the JUnit Vintage engine, addressing issue #2229.
concurrent execution
of test descriptors when parallel execution is enabled.planned
)Open Question
I haven’t yet worked on the part that handles reading configuration parameters, such as whether
parallel execution
should be enabled or the number of threads to be used.Is there a specific configuration format or approach you would recommend for this?
I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@API
annotations