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

Parallel execution of round trip tests #1845

Merged
merged 13 commits into from
Jun 17, 2023

Conversation

oowekyala
Copy link
Collaborator

The formatter round trip tests currently take about a minute on my machine. Using concurrent execution and a small refactoring this is now down to under 20secs.

I converted the test to use Junit dynamic tests, which means each individual test file gets its own test instance. This allows JUnit to parallelize them, and the IDE to display each test and its status separately. Additionally, the test is linked to the source file, so that if you click on it from the IDE you'll jump to the test file.

@@ -14,7 +14,10 @@ sourceSets {
}
test {
java {
srcDirs = ['src/test/java', 'test-gen']
srcDirs = ['src/test/java']
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this because both testFixtures and test used test-gen as a same source directory. Intellij does not support this. Since test depends on testFixtures there is no problem.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that explains why Intellij showed all these errors. Thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that test-gen is also removed from the test fixtures. Now I am wondering: why does this work?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it works because the PR adds a custom implementation of LfParsingTestHelper, which is the only class generated in test-gen.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! I don't know if we can disable the generation of the test-gen directory entirely, but at least it is ignored

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, we can disable it. See #1858

@oowekyala oowekyala force-pushed the clem.dynamic-tests branch from 578fe42 to 20371e0 Compare June 15, 2023 10:42
Copy link
Collaborator

@cmnrd cmnrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! This makes a lot of sense. We'll have to convince the CI as well though ;)

@lhstrh
Copy link
Member

lhstrh commented Jun 15, 2023

This is what CI complains about:

RoundTripTests > roundTripTestFactory() > initializationError FAILED
    java.lang.ExceptionInInitializerError
        at org.lflang.tests.compiler.RoundTripTests.roundTripTestFactory(RoundTripTests.java:44)

        Caused by:
        java.lang.RuntimeException: Cannot create a resource for 'file:/home/runner/work/lingua-franca/lingua-franca/test/C/src/PhysicalConnection.lf'; a registered resource factory is needed
            at org.eclipse.xtext.resource.XtextResourceSet.getResource(XtextResourceSet.java:263)
            at org.eclipse.xtext.resource.SynchronizedXtextResourceSet.getResource(SynchronizedXtextResourceSet.java:33)
            at org.lflang.tests.TestRegistry$TestDirVisitor.visitFile(TestRegistry.java:360)
            at org.lflang.tests.TestRegistry$TestDirVisitor.visitFile(TestRegistry.java:297)
            at java.base/java.nio.file.Files.walkFileTree(Files.java:2811)
            at java.base/java.nio.file.Files.walkFileTree(Files.java:2882)
            at org.lflang.tests.TestRegistry$TestDirVisitor.walk(TestRegistry.java:381)
            at org.lflang.tests.TestRegistry.<clinit>(TestRegistry.java:205)
            ... 1 more

@oowekyala
Copy link
Collaborator Author

Maybe this Junit feature can be used in the future to run the target tests concurrently, which would greatly speed them up as they spend large amounts of time waiting on IO.

Several versions of org.eclipse.core.runtime were being provided
to the integrationTest module, which made IntelliJ fail with a
SecurityException
@@ -21,7 +21,7 @@ dependencies {
testFixturesImplementation "org.junit.platform:junit-platform-commons:$jUnitPlatformVersion"
testFixturesImplementation "org.junit.platform:junit-platform-engine:$jUnitPlatformVersion"
testFixturesImplementation "org.opentest4j:opentest4j:$openTest4jVersion"
testFixturesImplementation "org.eclipse.xtext:org.eclipse.xtext.testing:$xtextVersion"
testFixturesImplementation platform("org.eclipse.xtext:org.eclipse.xtext.testing:$xtextVersion")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this magic incantation do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand it well, but it changes the version conflict resolution for dependencies. Previously, running tests from the integrationTest module in intellij failed with

java.lang.SecurityException: class "org.eclipse.core.runtime.OperationCanceledException"'s signer information does not match signer information of other classes in the same package

which indicates there are several jars on the classpath containing classes in this package --dependency hell.
The platform incantation forces the version conflict resolver to pick the dependency versions required by the 'platform', ie the versions it has been built and tested with. Without it, gradle is free to pick a newer version of each dependency independently, which resulted in an inconsistent dependency set apparently.

You can inspect how this affects our dependencies by running ./gradle :core:dependencies --configuration integrationTestRuntimeClasspath

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting.. Thanks for the fix and explaining this!!

Copy link
Member

@lhstrh lhstrh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

@lhstrh lhstrh enabled auto-merge June 17, 2023 01:08
@lhstrh lhstrh added testing enhancement Enhancement of existing feature labels Jun 17, 2023
@lhstrh lhstrh changed the title Use dynamic tests for formatter round trip tests Parallel execution of round trip tests Jun 17, 2023
@lhstrh lhstrh added this pull request to the merge queue Jun 17, 2023
Merged via the queue into lf-lang:master with commit 57e803f Jun 17, 2023
@oowekyala oowekyala deleted the clem.dynamic-tests branch June 17, 2023 12:33
@oowekyala
Copy link
Collaborator Author

Thanks for merging!

@cmnrd cmnrd mentioned this pull request Jun 19, 2023
@petervdonovan petervdonovan removed the enhancement Enhancement of existing feature label Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants