-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Prohibit JMH tests from having more than 2 forks #4075
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
Changes from all commits
d628f72
5a8daaa
780c92c
8b2d05e
de5ade5
697b463
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -144,6 +144,7 @@ dependencies { | |
|
|
||
| testImplementation 'org.testng:testng:7.11.0' // use for reactive streams test inheritance | ||
| testImplementation "com.tngtech.archunit:archunit-junit5:1.4.1" | ||
| testImplementation 'org.openjdk.jmh:jmh-core:1.37' // required for ArchUnit to check JMH tests | ||
|
|
||
| antlr 'org.antlr:antlr4:' + antlrVersion | ||
|
|
||
|
|
@@ -309,13 +310,17 @@ artifacts { | |
|
|
||
| List<TestDescriptor> failedTests = [] | ||
|
|
||
| test { | ||
| tasks.withType(Test) { | ||
| useJUnitPlatform() | ||
| testLogging { | ||
| events "FAILED", "SKIPPED" | ||
| exceptionFormat = "FULL" | ||
| } | ||
|
|
||
| // Required for JMH ArchUnit tests | ||
| classpath += sourceSets.jmh.output | ||
| dependsOn "jmhClasses" | ||
|
|
||
| afterTest { TestDescriptor descriptor, TestResult result -> | ||
| if (result.getFailedTestCount() > 0) { | ||
| failedTests.add(descriptor) | ||
|
|
@@ -327,34 +332,11 @@ tasks.register('testWithJava17', Test) { | |
| javaLauncher = javaToolchains.launcherFor { | ||
| languageVersion = JavaLanguageVersion.of(17) | ||
| } | ||
| useJUnitPlatform() | ||
| testLogging { | ||
| events "FAILED", "SKIPPED" | ||
| exceptionFormat = "FULL" | ||
| } | ||
|
|
||
| afterTest { TestDescriptor descriptor, TestResult result -> | ||
| if (result.getFailedTestCount() > 0) { | ||
| failedTests.add(descriptor) | ||
| } | ||
| } | ||
|
|
||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to common config |
||
| } | ||
| tasks.register('testWithJava11', Test) { | ||
| javaLauncher = javaToolchains.launcherFor { | ||
| languageVersion = JavaLanguageVersion.of(11) | ||
| } | ||
| useJUnitPlatform() | ||
| testLogging { | ||
| events "FAILED", "SKIPPED" | ||
| exceptionFormat = "FULL" | ||
| } | ||
|
|
||
| afterTest { TestDescriptor descriptor, TestResult result -> | ||
| if (result.getFailedTestCount() > 0) { | ||
| failedTests.add(descriptor) | ||
| } | ||
| } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to common config |
||
| } | ||
| test.dependsOn testWithJava17 | ||
| test.dependsOn testWithJava11 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |
|
|
||
| @Warmup(iterations = 2, time = 5, batchSize = 50) | ||
| @Measurement(iterations = 3, batchSize = 50) | ||
| @Fork(3) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix offending tests, even though these are in the |
||
| @Fork(2) | ||
| public class AssertBenchmark { | ||
|
|
||
| private static final int LOOPS = 100; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package graphql.archunit | ||
|
|
||
| import com.tngtech.archunit.core.domain.JavaClass | ||
| import com.tngtech.archunit.core.importer.ClassFileImporter | ||
| import com.tngtech.archunit.lang.ArchCondition | ||
| import com.tngtech.archunit.lang.ConditionEvents | ||
| import com.tngtech.archunit.lang.EvaluationResult | ||
| import com.tngtech.archunit.lang.SimpleConditionEvent | ||
| import org.openjdk.jmh.annotations.Fork | ||
| import spock.lang.Specification | ||
|
|
||
| import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes | ||
|
|
||
| class JMHForkArchRuleTest extends Specification { | ||
|
|
||
| def "JMH benchmarks on classes should not have a fork value greater than 2"() { | ||
| given: | ||
| def importedClasses = new ClassFileImporter() | ||
| .importPackages("benchmark", "performance", "graphql.execution") | ||
dondonz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def rule = classes() | ||
| .that().areAnnotatedWith(Fork.class) | ||
| .and().areTopLevelClasses() | ||
| .should(haveForkValueNotGreaterThan(2)) | ||
|
|
||
| when: | ||
| EvaluationResult result = rule.evaluate(importedClasses) | ||
|
|
||
| then: | ||
| !result.hasViolation() | ||
|
|
||
| cleanup: | ||
| if (result.hasViolation()) { | ||
| println result.getFailureReport().toString() | ||
| } | ||
| } | ||
|
|
||
| private static ArchCondition<JavaClass> haveForkValueNotGreaterThan(int maxFork) { | ||
| return new ArchCondition<JavaClass>("have a @Fork value of at most $maxFork") { | ||
| @Override | ||
| void check(JavaClass javaClass, ConditionEvents events) { | ||
| def forkAnnotation = javaClass.getAnnotationOfType(Fork.class) | ||
dondonz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (forkAnnotation.value() > maxFork) { | ||
| def message = "Class ${javaClass.name} has a @Fork value of ${forkAnnotation.value()} which is > $maxFork" | ||
| events.add(SimpleConditionEvent.violated(javaClass, message)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package graphql | ||
| package graphql.archunit | ||
|
|
||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| import com.tngtech.archunit.core.domain.JavaClasses | ||
| import com.tngtech.archunit.core.importer.ClassFileImporter | ||
|
|
||
There was a problem hiding this comment.
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