From 3630e0f723b5261ef108c477a4fb959d18adbb0b Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Mon, 23 Dec 2024 15:40:20 +0100 Subject: [PATCH 1/3] Fix a few infelicities in @WithTestResource documentation --- .../src/main/asciidoc/getting-started-testing.adoc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/src/main/asciidoc/getting-started-testing.adoc b/docs/src/main/asciidoc/getting-started-testing.adoc index 35c28cc97071a..aa1e151a1f5f0 100644 --- a/docs/src/main/asciidoc/getting-started-testing.adoc +++ b/docs/src/main/asciidoc/getting-started-testing.adoc @@ -1224,20 +1224,20 @@ public @interface WithRepeatableTestResource { } ---- -=== Usage of `@WithTestResources` +=== Usage of `@WithTestResource` -While test resources provided by `@QuarkusTestResource` are available either globally or restricted to the annotated test class (`restrictToAnnotatedClass`), the annotation `@WithTestResources` allows to additionally group tests by test resources for execution. -`@WithTestResources` has a `scope` property that takes a `TestResourceScope` enum value: +While test resources provided by `@QuarkusTestResource` are available either globally or restricted to the annotated test class (`restrictToAnnotatedClass`), the annotation `@WithTestResource` allows to additionally group tests by test resources for execution. +`@WithTestResource` has a `scope` property that takes a `TestResourceScope` enum value: - `TestResourceScope.MATCHING_RESOURCES` (default): Quarkus will group tests with the same test resources and run them together. After a group has been executed, all test resources will be stopped, and the next group will be executed. - `TestResourceScope.RESTRICTED_TO_CLASS`: The test resource is available only for the annotated test class and will be stopped after the test class has been executed. -- `TestResourceScope.GLOBAL`: Test resources apply to all tests in the testsuite +- `TestResourceScope.GLOBAL`: Test resources apply to all tests in the test suite Quarkus needs to restart if one of the following is true: -- At least one the existing test resources is restricted to the test class -- At least one the next test resources is restricted to the test class -- Different {@code MATCHING_RESOURCE} scoped test resources are being used +- At least one of the test resources of the current test is restricted to the test class +- At least one of the test resources of the next test is restricted to the test class +- Different `MATCHING_RESOURCES` scoped test resources are being used == Hang Detection From 4340d690ec05fccf5ed6ce204ac2ab890b22a6fd Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Mon, 23 Dec 2024 15:40:46 +0100 Subject: [PATCH 2/3] Fix a small typo in a variable name in QuarkusTestProfileAwareClassOrderer --- .../junit/util/QuarkusTestProfileAwareClassOrderer.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/util/QuarkusTestProfileAwareClassOrderer.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/util/QuarkusTestProfileAwareClassOrderer.java index a3d13b02f0436..9a9c4e683fe16 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/util/QuarkusTestProfileAwareClassOrderer.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/util/QuarkusTestProfileAwareClassOrderer.java @@ -122,12 +122,12 @@ public void orderClasses(ClassOrdererContext context) { }) .orElseGet(ClassName::new).orderClasses(context); - var classDecriptors = context.getClassDescriptors(); - var firstPassIndexMap = IntStream.range(0, classDecriptors.size()).boxed() - .collect(Collectors.toMap(classDecriptors::get, i -> String.format("%06d", i))); + var classDescriptors = context.getClassDescriptors(); + var firstPassIndexMap = IntStream.range(0, classDescriptors.size()).boxed() + .collect(Collectors.toMap(classDescriptors::get, i -> String.format("%06d", i))); // second pass: apply the actual Quarkus aware ordering logic, using the first pass indices as order key suffixes - classDecriptors.sort(Comparator.comparing(classDescriptor -> { + classDescriptors.sort(Comparator.comparing(classDescriptor -> { var secondaryOrderSuffix = firstPassIndexMap.get(classDescriptor); Optional customOrderKey = getCustomOrderKey(classDescriptor, context, secondaryOrderSuffix) .or(() -> getCustomOrderKey(classDescriptor, context)); From 48d51cdd253eddc6d3ff8b9db8cac87b4632fb11 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Mon, 23 Dec 2024 15:41:10 +0100 Subject: [PATCH 3/3] Make sure configAnnotation entry is always added Otherwise we were comparing items with and without this entry, leading to us restarting Quarkus a lot more often than necessary. Spotted while playing with a modified version of @WithKubernetesTestServer/ --- .../test/common/TestResourceManager.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/test-framework/common/src/main/java/io/quarkus/test/common/TestResourceManager.java b/test-framework/common/src/main/java/io/quarkus/test/common/TestResourceManager.java index b7dc8f2467de3..92439a7a1559a 100644 --- a/test-framework/common/src/main/java/io/quarkus/test/common/TestResourceManager.java +++ b/test-framework/common/src/main/java/io/quarkus/test/common/TestResourceManager.java @@ -106,8 +106,7 @@ public TestResourceManager(Class testClass, this.testResourceComparisonInfo = new HashSet<>(); for (TestResourceClassEntry uniqueEntry : uniqueEntries) { - testResourceComparisonInfo.add(new TestResourceComparisonInfo( - uniqueEntry.testResourceLifecycleManagerClass().getName(), uniqueEntry.getScope(), uniqueEntry.args)); + testResourceComparisonInfo.add(prepareTestResourceComparisonInfo(uniqueEntry)); } Set remainingUniqueEntries = initParallelTestResources(uniqueEntries); @@ -331,7 +330,7 @@ private Set uniqueTestResourceClassEntries(Path testClas } /** - * Allows Quarkus to extra basic information about which test resources a test class will require + * Allows Quarkus to extract basic information about which test resources a test class will require */ public static Set testResourceComparisonInfo(Class testClass, Path testClassLocation, List entriesFromProfile) { @@ -343,16 +342,24 @@ public static Set testResourceCo allEntries.addAll(entriesFromProfile); Set result = new HashSet<>(allEntries.size()); for (TestResourceClassEntry entry : allEntries) { - Map args = new HashMap<>(entry.args); - if (entry.configAnnotation != null) { - args.put("configAnnotation", entry.configAnnotation.annotationType().getName()); - } - result.add(new TestResourceComparisonInfo(entry.testResourceLifecycleManagerClass().getName(), entry.getScope(), - args)); + result.add(prepareTestResourceComparisonInfo(entry)); } return result; } + private static TestResourceComparisonInfo prepareTestResourceComparisonInfo(TestResourceClassEntry entry) { + Map args; + if (entry.configAnnotation != null) { + args = new HashMap<>(entry.args); + args.put("configAnnotation", entry.configAnnotation.annotationType().getName()); + } else { + args = entry.args; + } + + return new TestResourceComparisonInfo(entry.testResourceLifecycleManagerClass().getName(), entry.getScope(), + args); + } + private static Set getUniqueTestResourceClassEntries(Class testClass, Path testClassLocation, Consumer> afterMetaAnnotationAction) {