Skip to content

fix: make SpringBootConfigPropsTest immune to leaked metrics System properties - #16420

Open
jamespud wants to merge 1 commit into
apache:3.3from
jamespud:feature/fix-configprops-flaky-test
Open

fix: make SpringBootConfigPropsTest immune to leaked metrics System properties#16420
jamespud wants to merge 1 commit into
apache:3.3from
jamespud:feature/fix-configprops-flaky-test

Conversation

@jamespud

Copy link
Copy Markdown
Contributor

What is the purpose of the change

SpringBootConfigPropsTest intermittently fails in CI with expected: <prometheus> but was: <disabled> at SpringBootConfigPropsTest.java:106.

The module's metrics-disabling tests set the JVM System property dubbo.metrics.protocol=disabled. Dubbo's config resolution (Environment.getConfigurationMaps()) gives System properties the highest precedence, so depending on test execution order within the JVM fork, that property overrides this test's @SpringBootTest property dubbo.metrics.protocol=prometheus, and the assertion fails.

Root cause

  • dubbo-config-spring contains 30+ tests that set dubbo.metrics.protocol=disabled (some via SysProps.setProperty, i.e. real System properties) to disable metrics in their scenarios.
  • The failing test binds MetricsConfig through Dubbo's own configuration chain, where SystemConfiguration ranks first — higher than the Spring inlined test property.
  • When a leaked System property survives into this test's context creation (execution-order dependent), MetricsConfig.protocol becomes disabled.

Reproduction (before fix):
mvn -pl dubbo-config/dubbo-config-spring -am test -Dtest=SpringBootConfigPropsTest -Ddubbo.metrics.protocol=disabled fails with the same assertion.

Brief changelog

  1. SpringBootConfigPropsTest / SpringBootMultipleConfigPropsTest: in @BeforeAll, clear the leaked dubbo.metrics.protocol / dubbo.metrics.enabled System properties before DubboBootstrap.reset(), so prometheus is always bound regardless of prior test state.
  2. SysProps (dubbo-config-spring / dubbo-config-api test helpers and dubbo-test-common): make reset() also clear the recorded System properties (previously it only cleared the internal map), removing the footgun that could leak such properties between tests.

Verifying the change

  • After fix, the reproduction command (-Ddubbo.metrics.protocol=disabled) passes for both SpringBootConfigPropsTest and SpringBootMultipleConfigPropsTest.
  • Regression: SysProps-related tests in dubbo-config-spring (ConfigTest, DubboConfigAliasPostProcessorTest, DubboNamespaceHandlerTest, JavaConfigBeanTest, etc.) and dubbo-config-api (ConfigCenterConfigTest, ServiceConfigTest, ApplicationConfigTest, ReferenceCacheTest, MultiInstanceTest) all pass.
  • Spotless passes on all three modules.

…roperties

SpringBootConfigPropsTest intermittently fails in CI with 'expected: <prometheus> but was: <disabled>'. The module's metrics-disabling tests set the JVM System property dubbo.metrics.protocol=disabled, and Dubbo's config resolution gives System properties the highest precedence, so depending on test execution order it overrides the test's @SpringBootTest property dubbo.metrics.protocol=prometheus.

Changes:
- SpringBootConfigPropsTest / SpringBootMultipleConfigPropsTest: clear the leaked dubbo.metrics.protocol / dubbo.metrics.enabled System properties in @BeforeAll before DubboBootstrap.reset(), so prometheus is bound regardless of prior test state.
- SysProps (dubbo-config-spring and dubbo-config-api test helpers, dubbo-test-common): make reset() also clear the recorded System properties (previously it only cleared the internal map), removing the footgun that could leak such properties between tests.
@codecov-commenter

codecov-commenter commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.89%. Comparing base (3a30432) to head (860eefa).

Additional details and impacted files
@@             Coverage Diff              @@
##                3.3   #16420      +/-   ##
============================================
+ Coverage     60.87%   60.89%   +0.01%     
+ Complexity    11766    11763       -3     
============================================
  Files          1953     1953              
  Lines         89273    89273              
  Branches      13473    13473              
============================================
+ Hits          54346    54363      +17     
+ Misses        29333    29314      -19     
- Partials       5594     5596       +2     
Flag Coverage Δ
integration-tests-java21 32.13% <ø> (-0.02%) ⬇️
integration-tests-java8 32.21% <ø> (ø)
samples-tests-java21 32.14% <ø> (-0.06%) ⬇️
samples-tests-java8 29.71% <ø> (-0.08%) ⬇️
unit-tests-java11 59.10% <ø> (-0.02%) ⬇️
unit-tests-java17 58.60% <ø> (-0.04%) ⬇️
unit-tests-java21 58.60% <ø> (-0.01%) ⬇️
unit-tests-java25 58.54% <ø> (-0.03%) ⬇️
unit-tests-java8 59.16% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants