Skip to content

Conversation

@dondonz
Copy link
Member

@dondonz dondonz commented Aug 2, 2025

Fixes #4010. Adds an ArchUnit test to prohibit JMH tests that use more than 2 forks. This is to save time in our automated testing pipeline, because extra forks don't add much value.

I had to update our test config because our JMH benchmarks are not in the usual package as everything else. ArchUnit reads .class files. Without this configuration change, ArchUnit can't read any JMH tests.

While I'm here I also:

  • Tidied up the test config, to reduce repetition
  • Changed all offending JMH tests to 2 forks, even if they don't run in the automated pipeline (in performance), because I'd rather we apply this rule equally to all benchmarks
  • Created a new home for ArchUnit tests, make it easier to find

Sample error output

Architecture Violation [Priority: MEDIUM] - Rule 'classes that are annotated with @Fork and are top level classes should have a @Fork value of at most 2' was violated (17 times):
Class benchmark.AssertBenchmark has a @Fork value of 3 which is > 2
Class benchmark.AstPrinterBenchmark has a @Fork value of 3 which is > 2
Class benchmark.ChainedInstrumentationBenchmark has a @Fork value of 3 which is > 2
Class benchmark.CompletableFuturesBenchmark has a @Fork value of 3 which is > 2
Class benchmark.CreateExtendedSchemaBenchmark has a @Fork value of 3 which is > 2
Class benchmark.CreateSchemaBenchmark has a @Fork value of 3 which is > 2
Class benchmark.GetterAccessBenchmark has a @Fork value of 3 which is > 2
Class benchmark.IntMapBenchmark has a @Fork value of 3 which is > 2
Class benchmark.IntrospectionBenchmark has a @Fork value of 3 which is > 2
Class benchmark.MapBenchmark has a @Fork value of 3 which is > 2
Class benchmark.OverlappingFieldValidationBenchmark has a @Fork value of 3 which is > 2
Class benchmark.PropertyFetcherBenchMark has a @Fork value of 3 which is > 2
Class benchmark.SchemaTransformerBenchmark has a @Fork value of 3 which is > 2
Class benchmark.SimpleQueryBenchmark has a @Fork value of 3 which is > 2
Class benchmark.TwitterBenchmark has a @Fork value of 3 which is > 2
Class benchmark.TypeDefinitionParserVersusSerializeBenchmark has a @Fork value of 3 which is > 2
Class benchmark.ValidatorBenchmark has a @Fork value of 3 which is > 2

List<TestDescriptor> failedTests = []

test {
tasks.withType(Test) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Reorganising tests: let's have a common set of config across all Test tasks

failedTests.add(descriptor)
}
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to common config

if (result.getFailedTestCount() > 0) {
failedTests.add(descriptor)
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to common config


@Warmup(iterations = 2, time = 5, batchSize = 50)
@Measurement(iterations = 3, batchSize = 50)
@Fork(3)
Copy link
Member Author

Choose a reason for hiding this comment

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

Fix offending tests, even though these are in the benchmark package, and not performance (used by the automated pipeline)

@@ -1,4 +1,4 @@
package graphql
package graphql.archunit

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to write a few more ArchUnit tests, let's start organising them in 1 place

@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2025

Test Results

  324 files    324 suites   3m 26s ⏱️
5 017 tests 5 011 ✅ 6 💤 0 ❌
5 106 runs  5 100 ✅ 6 💤 0 ❌

Results for commit 697b463.

@dondonz dondonz added this to the 25.x breaking changes milestone Aug 2, 2025
@dondonz dondonz requested a review from Copilot August 3, 2025 05:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds an ArchUnit test to enforce a maximum of 2 forks for JMH benchmarks to optimize CI pipeline performance, as additional forks provide diminishing returns in automated testing environments.

  • Creates a new ArchUnit rule to validate JMH @Fork annotations don't exceed value of 2
  • Updates all existing JMH benchmark classes to use @Fork(2) instead of @Fork(3)
  • Reorganizes ArchUnit tests into dedicated graphql.archunit package for better organization

Reviewed Changes

Copilot reviewed 19 out of 20 changed files in this pull request and generated 2 comments.

File Description
src/test/groovy/graphql/archunit/NullabilityAnnotationUsageTest.groovy Moved to new archunit package
src/test/groovy/graphql/archunit/JMHForkArchRuleTest.groovy New ArchUnit test enforcing max 2 forks for JMH benchmarks
src/jmh/java/benchmark/*.java Updated 17 benchmark classes to use @Fork(2) instead of @Fork(3)

@dondonz dondonz merged commit 21bcb4a into master Aug 7, 2025
2 checks passed
@dondonz dondonz deleted the ban-fork-2 branch August 7, 2025 01:02
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.

Add validation to restrict JMH benchmarks to 2 forks

2 participants