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

Allow anonymous test extension subclasses to share the test state of their parents #45818

Conversation

holly-cummins
Copy link
Contributor

The Quarkus test infrastructure holds state about various things, including references to the currently running Quarkus application. It wants state to be shareable between tests of the same type (normal test, integration test, component test, etc), but not shareable between those different types. To do this, it uses the class name of the test extension as a key. These type all have a common parent, so it needs to be careful with checks based on the hierarchy.

This normally works well, but in my test classloading runs, I hit a problem where state should have been shared, and was not. HibernatePropertiesTest uses an anonymous subclass to change the behaviour of QuarkusTestExtension. That means it can't share state with other tests in the same project.

  @RegisterExtension
        static QuarkusTestExtension TEST = new QuarkusTestExtension() {
         @Override
          ... 

I think we don't want to 'count' the class of anonymous classes as different, since they're clearly supposed to 'be' the superclass.

(Why did I see the problem, when main is working fine? It was either because my code changed the test order, or because the new logic is a bit more dependent on the state. I've already forgotten, because it was a whole day ago. However, I think it's possible for other tests running against normal-Quarkus to potentially hit this problem, if they're adventurous enough to do the subclassing. )

Copy link
Contributor

@geoand geoand left a comment

Choose a reason for hiding this comment

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

Interesting edge case!

Copy link

quarkus-bot bot commented Jan 23, 2025

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit 5c5c425.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.


Flaky tests - Develocity

⚙️ JVM Tests - JDK 17

📦 integration-tests/opentelemetry

io.quarkus.it.opentelemetry.MetricsTest.directCounterTest - History

  • Condition with Lambda expression in io.quarkus.it.opentelemetry.MetricsTest was not fulfilled within 5 seconds. - org.awaitility.core.ConditionTimeoutException
org.awaitility.core.ConditionTimeoutException: Condition with Lambda expression in io.quarkus.it.opentelemetry.MetricsTest was not fulfilled within 5 seconds.
	at org.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:167)
	at org.awaitility.core.CallableCondition.await(CallableCondition.java:78)
	at org.awaitility.core.CallableCondition.await(CallableCondition.java:26)
	at org.awaitility.core.ConditionFactory.until(ConditionFactory.java:1006)
	at org.awaitility.core.ConditionFactory.until(ConditionFactory.java:975)
	at io.quarkus.it.opentelemetry.MetricsTest.directCounterTest(MetricsTest.java:57)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)

⚙️ JVM Tests - JDK 21

📦 integration-tests/observability-lgtm

io.quarkus.observability.test.LgtmResourcesTest.testTracing - History

  • java.lang.RuntimeException: Failed to start quarkus - java.lang.RuntimeException
java.lang.RuntimeException: java.lang.RuntimeException: Failed to start quarkus
	at io.quarkus.test.junit.QuarkusTestExtension.throwBootFailureException(QuarkusTestExtension.java:611)
	at io.quarkus.test.junit.QuarkusTestExtension.interceptTestClassConstructor(QuarkusTestExtension.java:695)
	at java.base/java.util.Optional.orElseGet(Optional.java:364)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: java.lang.RuntimeException: Failed to start quarkus
	at io.quarkus.runner.ApplicationImpl.doStart(Unknown Source)

📦 integration-tests/oidc-client-wiremock

io.quarkus.it.keycloak.OidcClientTest.testGetAccessTokenWithConfiguredExpiresIn - History

  • expected: <true> but was: <false> - org.opentest4j.AssertionFailedError
org.opentest4j.AssertionFailedError: expected: <true> but was: <false>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:31)
	at org.junit.jupiter.api.Assertions.assertTrue(Assertions.java:183)
	at io.quarkus.it.keycloak.OidcClientTest.testGetAccessTokenWithConfiguredExpiresIn(OidcClientTest.java:68)

⚙️ JVM Tests - JDK 17 Windows

📦 extensions/micrometer-opentelemetry/deployment

io.quarkus.micrometer.opentelemetry.deployment.compatibility.MicrometerTimedInterceptorTest.testTimeMethod - History

  • Stream has no elements - java.lang.IllegalArgumentException
java.lang.IllegalArgumentException: Stream has no elements
	at io.quarkus.micrometer.opentelemetry.deployment.common.MetricDataFilter.lambda$lastReading$2(MetricDataFilter.java:213)
	at java.base/java.util.Optional.orElseThrow(Optional.java:403)
	at io.quarkus.micrometer.opentelemetry.deployment.common.MetricDataFilter.lastReading(MetricDataFilter.java:213)
	at io.quarkus.micrometer.opentelemetry.deployment.common.MetricDataFilter.lastReadingDataPoint(MetricDataFilter.java:231)
	at io.quarkus.micrometer.opentelemetry.deployment.compatibility.MicrometerTimedInterceptorTest.testTimeMethod(MicrometerTimedInterceptorTest.java:77)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at io.quarkus.test.QuarkusUnitTest.runExtensionMethod(QuarkusUnitTest.java:513)

⚙️ Native Tests - Messaging1

📦 integration-tests/reactive-messaging-kafka

io.quarkus.it.kafka.KafkaConnectorIT.testRequestReply - History

  • iterable contents differ at index [2], expected: <reply-3> but was: <{"details":"Error id 6fdfef06-8a2a-4e6b-9b26-baff719901d2-1","stack":""}> - org.opentest4j.AssertionFailedError
org.opentest4j.AssertionFailedError: iterable contents differ at index [2], expected: <reply-3> but was: <{"details":"Error id 6fdfef06-8a2a-4e6b-9b26-baff719901d2-1","stack":""}>
	at io.quarkus.it.kafka.KafkaConnectorTest.testRequestReply(KafkaConnectorTest.java:112)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at io.quarkus.test.junit.QuarkusTestExtension.interceptTestMethod(QuarkusTestExtension.java:789)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
  • iterable contents differ at index [0], expected: <reply-1> but was: <{"details":"Error id 6fdfef06-8a2a-4e6b-9b26-baff719901d2-1","stack":""}> - org.opentest4j.AssertionFailedError
org.opentest4j.AssertionFailedError: iterable contents differ at index [0], expected: <reply-1> but was: <{"details":"Error id 6fdfef06-8a2a-4e6b-9b26-baff719901d2-1","stack":""}>
	at io.quarkus.it.kafka.KafkaConnectorTest.testRequestReply(KafkaConnectorTest.java:112)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at io.quarkus.test.junit.QuarkusTestExtension.interceptTestMethod(QuarkusTestExtension.java:789)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
  • iterable contents differ at index [0], expected: <reply-1> but was: <{"details":"Error id 6fdfef06-8a2a-4e6b-9b26-baff719901d2-1","stack":""}> - org.opentest4j.AssertionFailedError
org.opentest4j.AssertionFailedError: iterable contents differ at index [0], expected: <reply-1> but was: <{"details":"Error id 6fdfef06-8a2a-4e6b-9b26-baff719901d2-1","stack":""}>
	at io.quarkus.it.kafka.KafkaConnectorTest.testRequestReply(KafkaConnectorTest.java:112)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at io.quarkus.test.junit.QuarkusTestExtension.interceptTestMethod(QuarkusTestExtension.java:789)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

@geoand geoand merged commit afc43d3 into quarkusio:main Jan 23, 2025
51 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.19 - main milestone Jan 23, 2025
@holly-cummins holly-cummins deleted the better-state-sharing-for-anonymous-test-extensions branch January 24, 2025 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

2 participants