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

Run tests in parallel on different JVM forks #3068

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

bdemers
Copy link

@bdemers bdemers commented Jun 3, 2024

Low hanging fruit for running tests in parallel is forking multiple JVMs (1C, one per core) and having each one run tests sequentially.
This cuts the build time from 5m to 2m on my laptop.

NOTE: I was writing up my thoughts on other ways to run the tests in parallel without needing to fork, but then I realized all the tests are using "mongodb://localhost:27017/" + TEST_DB_NAME;, so I'm not sure how running my tests worked?
Answer:

String mongodb = System.getProperty("mongodb");
String connectionString;
MongoDBContainer mongoDBContainer = null;
if ("local".equals(mongodb)) {

@evanchooly I was chatting with @trishagee to get the tests to run in parallel.

bdemers added a commit to bdemers/morphia that referenced this pull request Jun 5, 2024
Creates a db for each test class, tests classes are run in parallel, methods within a class are sequential.

Ignoring the test failures below, this runs in _about_ the same amount of time as MorphiaOrg#3068

- JVM forks of `1C` on an Mac M1 Max was ~2min (in above PR)
- A single JVM with 20 threads ran in 2 min (increasing this 40 threads saved another 15 seconds)

Results may vary depnding on OS, specs, where docker is running, etc

There are still 5 test failures:

```
[ERROR] Failures:
[ERROR]   TestVersioning.testAlternateFailures:97->MorphiaTestSetup.withTestConfig:177->MorphiaTestSetup.withConfig:199->lambda$testAlternateFailures$1:100 Expected MongoWriteException to be thrown, but nothing was thrown
[ERROR]   TestIndexes.shouldNotAllowMultipleTextIndexes » Test Method TestIndexes.shouldNotAllowMultipleTextIndexes()[pri:0, instance:dev.morphia.test.indexes.TestIndexes@411341bd] should have thrown an exception of type class com.mongodb.MongoCommandException
[ERROR]   PathTargetTest.arrays:51->MorphiaTestSetup.withTestConfig:181->MorphiaTestSetup.withTestConfig:177->MorphiaTestSetup.withConfig:199->lambda$arrays$0:56 » Validation Could not resolve path 'listEmbeddedType.1.anotherField' against 'dev.morphia.test.internal.PathTargetTest$EntityWithListsAndArrays'.  Unknown path element: 'anotherField'.
[ERROR]   PathTargetTest.interfaces:88->MorphiaTestSetup.withTestConfig:181->MorphiaTestSetup.withTestConfig:177->MorphiaTestSetup.withConfig:199->lambda$interfaces$3:95 » Validation Could not resolve path 'mapped.value' against 'dev.morphia.test.internal.PathTargetTest$HoldsAnInterface'.  Unknown path element: 'value'.
[ERROR]   TestMapping.testExternalClass:377 Expected MappingException to be thrown, but nothing was thrown
```

NOTE: This code needs to be cleaned up and DRY'd a bit, it's hacky now.
@bdemers
Copy link
Author

bdemers commented Jun 5, 2024

A bit more hacking, and I was able to get most (all but 5) of the tests working running in parallel in a single JVM: bdemers@45cd1c6

Not sure if it's worth it or not, it runs in about the same amount of time, as this PR (which is basically a single config arg)
See notes in the above commit if interested.

Or you could just run against master: ./mvnw -DforkCount=1C

@evanchooly
Copy link
Member

I think what you're running into is that MorphiaContainer was added to try and solve a particular problem ("clear" boundaries around configuration reuse and avoiding remapping classes) but it doesn't really solve that problem and makes things way more complicated than it's worth. I've half intended to remove it but never really had a big enough motivator but I think maybe now is a good time.

If each class runs off in its own forked env/thread/whatever, we can simply rebuild it all each time (yes, we'll remap code more than we need but i'm working on optimizing that, too) and simply run each test with its own database. Then we won't have to worry about dropping databases while trying to write to them. In fact, there's no need to drop the databases anymore since they all run on ephemeral testcontainers instances. Let me see about unwinding the MorphiaContainer junk and see if that makes your life any easier.

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

Successfully merging this pull request may close these issues.

2 participants