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

Tests in MetricsIntegrationTests are non idempotent #38604

Closed
SaaiVenkat opened this issue Nov 29, 2023 · 1 comment
Closed

Tests in MetricsIntegrationTests are non idempotent #38604

SaaiVenkat opened this issue Nov 29, 2023 · 1 comment
Assignees
Labels
type: task A general task
Milestone

Comments

@SaaiVenkat
Copy link

SaaiVenkat commented Nov 29, 2023

Issue

  • The tests in org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsIntegrationTests, specifically requestMappingIsInstrumented() and restTemplateIsInstrumented() are not idempotent, since they pollute the state registry
  • This might fail future tests that share the same state similar to CloudFoundry endpoint integration tests are order dependent #38363
  • AssertionFailedError log when restTemplateIsInstrumented was run twice in the same JVM
org.opentest4j.AssertionFailedError: 
expected: 1L
 but was: 2L
	at [email protected]/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at [email protected]/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
	at [email protected]/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at [email protected]/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
	at app//org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsIntegrationTests.restTemplateIsInstrumented(MetricsIntegrationTests.java:111)
  • AssertionFailedError log when requestMappingIsInstrumented was run twice in the same JVM
org.awaitility.core.ConditionTimeoutException: Assertion condition defined as a org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsIntegrationTests 
expected: 1L
 but was: 2L within 5 seconds.
	at app//org.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:167)
	at app//org.awaitility.core.AssertionCondition.await(AssertionCondition.java:119)
	at app//org.awaitility.core.AssertionCondition.await(AssertionCondition.java:31)
	at app//org.awaitility.core.ConditionFactory.until(ConditionFactory.java:985)
	at app//org.awaitility.core.ConditionFactory.untilAsserted(ConditionFactory.java:769)
	at app//org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsIntegrationTests.requestMappingIsInstrumented(MetricsIntegrationTests.java:118)

Cause

Steps to reproduce

  • Run each of the above mentioned test twice in the same JVM using @RepeatedTest(2)

Proposed Fix

  • Since the registry's timer state is polluted across different runs, I have reset the registry state before each test run
  • Added a setUp() with @BeforeEach where the registry state is cleared using this.registry.clear()
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 29, 2023
@philwebb philwebb changed the title Tests in MetricsIntegrationTests are non idempotent Tests in MetricsIntegrationTests are non idempotent Nov 29, 2023
@mhalbritter mhalbritter added type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 30, 2023
@mhalbritter mhalbritter added this to the 3.1.x milestone Nov 30, 2023
@mhalbritter mhalbritter self-assigned this Nov 30, 2023
@mhalbritter
Copy link
Contributor

Thanks for the analysis! I've fixed that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: task A general task
Projects
None yet
Development

No branches or pull requests

3 participants