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

Update Groovy and Spock versions #4840

Merged

Conversation

nikita-tkachenko-datadog
Copy link
Contributor

@nikita-tkachenko-datadog nikita-tkachenko-datadog commented Mar 3, 2023

What Does This Do

Updates Groovy version (2.5 -> 3.0) and Spock version (1.3 -> 2.1).
Migrates all tests that used to run on JUnit 4 to JUnit 5.

Motivation

Our current version of Spock is 1.3.
It only support Groovy 2.x, which has some drawbacks:

Additional Notes

SpockRunner that we use to run instrumentation tests cannot be properly ported to JUnit 5, since the framework does not provide the hooks / extension points that can be used to shadow the tested class (see Introduce extension API for providing a custom ClassLoader (e.g. for Powermock)).

In order to mitigate this, SpockRunner was changed to extend JUnitPlatform, which is a JUnit 4 runner that allows executing JUnit 5 tests in a JUnit 4 environment (i.e. running them as JUnit 4 tests).

So even though Spock 2 tests run on top of JUnit 5, we execute them in "compatibility mode" so that SpockRunner could shadow the test class (see SputnikRunner removed for more details).

@nikita-tkachenko-datadog nikita-tkachenko-datadog force-pushed the nikita-tkachenko/spock-and-groovy-update branch from d1a62af to 41c8c78 Compare March 6, 2023 11:20
This was referenced Mar 6, 2023
@nikita-tkachenko-datadog nikita-tkachenko-datadog force-pushed the nikita-tkachenko/spock-and-groovy-update branch 2 times, most recently from 5bd62a8 to e95d721 Compare March 6, 2023 21:56
Copy link
Contributor

@PerfectSlayer PerfectSlayer left a comment

Choose a reason for hiding this comment

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

Great work 👏

I wonder if it will be an issue for the junit-4 and junit-5 instrumentation to not properly test the minimal version supported. I will try to get some feedback on it.
In the meantime, I left you some comments.

@@ -1,5 +1,5 @@
final class CachedData {
static groovyVer = "2.5.21"
static groovyVer = "3.0.10"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not using groovy 4?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One of the reasons for doing this change was to be able to use gradleTestKit(), and the one that comes with our Gradle version uses Groovy 3.0.10.
If I update it to Groovy 4 I am afraid the issue will be the same as before, only this time Spock's Groovy will be newer than the test kit's one, not older.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I tried to bump Groovy version to version 4 but I had to leave it to 3 for Gradle plugins for example.
Is there any specific module(s) that would requires version 3 for your tests or will it impact the whole project?
I wonder if it could be doable (and recommended) to update to 4 while leaving some module to 3 (like we did for JUnit4/5).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will be just one module that does Gradle instrumentation. Technically it would be possible, of course, to have that specific module use Groovy 3, but it would complicate things too much in my opinion (as that module depends on a couple of common testing modules which themselves depend on Groovy).
Perhaps it would be simpler to migrate to Groovy 4 together with Gradle wrapper update, to avoid the need to have multiple versions.

@@ -10,9 +10,8 @@ final class CachedData {
okhttp_legacy : "[3.0,3.12.12]", // 3.12.x is last version to support Java7)
okio : "1.16.0",

spock : "1.3-groovy-$spockGroovyVer",
spock : "2.1-groovy-$spockGroovyVer",
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question here: why not using latest Spock version 2.3?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initial intention was to do the minimal upgrade required to use Groovy 3. I will try the newest version to see if it doesn't require further changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some strange reason, upgrading Groovy from 3.0.10 to 3.0.11 breaks tests in :dd-java-agent:instrumentation:netty-4.1:test module.
This blocks upgrading Spock.

I assume it's some transitive dependency change in Groovy that is to blame (my prime suspect is asm, which has been bumped from 9.2 to 9.3), but I wasn't able to prove it.

I cannot dedicate much more time to this change at the moment, so my suggestion would be staying on Groovy 3.0.10 / Spock 2.1 combination for now, and then possibly upgrading them later as a separate change

Copy link
Member

Choose a reason for hiding this comment

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

Personally, I wouldn't mind upgrading Groovy and Spock in separate PR, since these will probably require many more fixes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure. About my above comment, this question (global groovy 4 with some groovy 3 modules) can be investigate later in another PR in you have other priorities right now.

gradle/dependencies.gradle Outdated Show resolved Hide resolved
gradle/dependencies.gradle Outdated Show resolved Hide resolved
dd-java-agent/instrumentation/build.gradle Outdated Show resolved Hide resolved
@nikita-tkachenko-datadog
Copy link
Contributor Author

nikita-tkachenko-datadog commented Mar 7, 2023

I wonder if it will be an issue for the junit-4 and junit-5 instrumentation to not properly test the minimal version supported.

Yeah, I am not too happy about this, but there isn't an alternative that I can think of.
Test framework instrumentations are only used by CI Visibility, so I would be the person responsible for supporting them.
I can live with that, since it doesn't seem to be too much of a burden to do basic manual checks to ensure minimum versions work.
Although I am open to discussion of course.

@nikita-tkachenko-datadog nikita-tkachenko-datadog changed the title WIP: update spock version Update Groovy and Spock versions Mar 7, 2023
@PerfectSlayer
Copy link
Contributor

Yeah, I am not too happy about this, but there isn't an alternative that I can think of.

We could start thinking of moving away from SpockRunner by creating an agent to load bootstrap classes into bootstrap classloader (like the dd-java-agent.jar but that only alter the classpath) and run tests with the agent on a forked VM.
It should work but it feels way out of the scope of this PR, especially if you (as JUnit integration maintainer) can live with this PR change 😅

@nikita-tkachenko-datadog nikita-tkachenko-datadog force-pushed the nikita-tkachenko/spock-and-groovy-update branch from f8b19af to f20c2e3 Compare March 7, 2023 13:50
@nikita-tkachenko-datadog nikita-tkachenko-datadog marked this pull request as ready for review March 7, 2023 15:37
@nikita-tkachenko-datadog nikita-tkachenko-datadog requested a review from a team March 7, 2023 15:37
@nikita-tkachenko-datadog nikita-tkachenko-datadog requested review from a team as code owners March 7, 2023 15:37
@nikita-tkachenko-datadog nikita-tkachenko-datadog requested review from ojung and removed request for a team March 7, 2023 15:37
Copy link
Member

@jpbempel jpbempel left a comment

Choose a reason for hiding this comment

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

LGTM for debugger

Copy link
Member

@smola smola left a comment

Choose a reason for hiding this comment

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

Great job!

@PerfectSlayer
Copy link
Contributor

Seems all good. Can you squash the commits when merging? 🙏

@nikita-tkachenko-datadog nikita-tkachenko-datadog merged commit 2dbc617 into master Mar 9, 2023
@nikita-tkachenko-datadog nikita-tkachenko-datadog deleted the nikita-tkachenko/spock-and-groovy-update branch March 9, 2023 15:38
@github-actions github-actions bot added this to the 1.11.0 milestone Mar 9, 2023
@bantonsson bantonsson modified the milestones: 1.11.0, new 1.11.0 Mar 17, 2023
@smola smola added comp: testing Testing tag: no release notes Changes to exclude from release notes labels Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp: testing Testing tag: dependencies Dependencies related changes tag: no release notes Changes to exclude from release notes type: refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants