Skip to content
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

Extension to execute test multiple times in parallel #647

Open
Bukama opened this issue May 31, 2022 · 5 comments
Open

Extension to execute test multiple times in parallel #647

Bukama opened this issue May 31, 2022 · 5 comments

Comments

@Bukama
Copy link
Member

Bukama commented May 31, 2022

In one of our apps at work we recognized an error which somehow/sometimes happens when executing it in paralell. To be exactly it's an app with an REST-API and the error occurs sometimes, when it's called multiple times in short interval.

While trying to reproduce the error and writing a test for it a team mate asked me if I know a way to execute the same JUnit test multiple ties in parallel. But by default there is no way to do this. JUnit by itself only allows to configure execute test(classes) in parallel or as a sequence (see JUnit Userguide 2.19).

For the exact need of calling a REST-API (or other forms of webservice) we found the zerocode extension, but we don't like the way tests are configured. Before we found that, my first thought was "one could write a JUnit extension for that". And well here's the bishue :D

My idea would be an annotation like @ParallelExecution with an parameter for the number of parallel executions. The extension then runs the test multiple times, similar to the RetryingTest extesion.

@Test
@ParallelExectution(5)
void fiveTimesInParallel() {
  // test code
}
@Michael1993
Copy link
Member

I've been thinking about this the last couple of days. Unfortunately I'm not really familiar with the multithreading in Java. 😔
I've been reading up a bit and I think I might have an idea. Will try a draft this weekend hopefully 🙏

@Michael1993
Copy link
Member

Michael1993 commented Aug 6, 2022

I have something that I have no idea how to test. 😅

But if it works then it was a lot easier then I expected, since I can just let JUnit execute the tests in parallel for me - no multithreading knowledge required...?

@beatngu13
Copy link
Member

I assume such an extension would also require some kind of "special" setup and/or TestInstance.Lifecycle, since one doesn't want the class under test to be reinstantiated during the parallel execution?

@nipafx
Copy link
Member

nipafx commented Nov 8, 2022

Hey @Michael1993 , you wanna let us know about the magic implementation you came up with? 🧐

@Michael1993
Copy link
Member

Hey @Michael1993 , you wanna let us know about the magic implementation you came up with? 🧐

Yeah, it was me being dumb again, sorry. 😓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants