Skip to content

test(config-data): isolate environment and cache state - #148

Merged
nobodyiam merged 1 commit into
apolloconfig:mainfrom
nobodyiam:codex/fix-config-data-test-isolation
Oct 17, 2026
Merged

nobodyiam merged 1 commit into
apolloconfig:mainfrom
nobodyiam:codex/fix-config-data-test-isolation

Conversation

@nobodyiam

@nobodyiam nobodyiam commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

What's the purpose of this PR

Fix order-dependent ConfigData tests. PureApolloConfigTest sets env=local; clearing the system property afterward did not refresh Foundation's cached server environment. When this test ran first, ConfigDataIntegrationTest stayed in local mode, skipped MockWebServer, and read missing cache files instead of the expected configuration. The integration fixture also needs its own disposable disk cache so MockWebServer responses do not read or overwrite a caller's cache.

Which issue(s) this PR fixes:

No standalone issue. Discovered while reviewing #147. The same two failures also occur in the control CI run, whose code matches main except for CHANGES.md.

Brief changelog

  • Save and restore the pure-config fixture's existing env and spring.profiles.active properties, and refresh Foundation's cached server provider during setup and teardown.
  • Run the MockWebServer integration tests explicitly in dev mode and refresh the provider when entering and leaving their environment scope.
  • Give the integration class a temporary cache directory that wraps the Apollo/server rules, reapply it after each property reset, and delete it on both successful and failing runs while restoring the caller's cache property.

Validation

Using JDK 8: full suite reports 708 tests, 4 skipped, no failures or errors.

  • mvn -B clean test -P travis jacoco:report -Dmaven.gitcommitid.skip=true
  • mvn -B spotless:check -Dmaven.gitcommitid.skip=true
  • mvn -B -f apollo-compat-tests/pom.xml spotless:check -Dmaven.gitcommitid.skip=true

Additional isolated-JVM checks cover the failing CI class order, integration-before-pure order, and integration tests starting with -Denv=local.

A disk-cache probe with both a caller-supplied apollo.cache-dir and APOLLO_CACHE_DIR fails before the cache fix: the integration tests pass but leave three fixture cache files in a caller directory. After the fix, both tests persist only inside one temporary directory, both caller directories remain unchanged, the original cache property is restored, and the temporary directory is removed. A separate intentional-failure probe also verifies directory cleanup and property restoration.

  • Read the Contributing Guide.
  • Describe the root cause, change, and validation.
  • Verify formatting in both Maven reactors with spotless:check.
  • Validate existing tests with explicit class orders and isolated-cache probes.
  • Run the full unit/integration test suite.
  • Assess changelog impact: test-only isolation fix; no user-visible SDK behavior changes, so no release-note entry is added.

Copilot AI balanced review requested due to automatic review settings October 17, 2026 01:54
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-17T02:24:34.548378Z 5682d60 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2970966c-0c1d-41a0-a113-147ba709be97
📥 Commits

Reviewing files that changed from the base of the PR and between 169f407 and 8985b7f.

📒 Files selected for processing: 3
  • apollo-client-config-data/src/test/java/com/ctrip/framework/apollo/config/data/importer/PureApolloConfigIsolationTest.java
  • apollo-client-config-data/src/test/java/com/ctrip/framework/apollo/config/data/importer/PureApolloConfigTest.java
  • apollo-client-config-data/src/test/java/com/ctrip/framework/apollo/config/data/integration/ConfigDataIntegrationTest.java

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

Config data tests now restore environment and profile properties and refresh Foundation’s cached environment. The integration test uses dev instead of local.

Changes: Config data test environment isolation

Layer / File(s) Summary
Pure Apollo property restoration
apollo-client-config-data/src/test/java/com/ctrip/framework/apollo/config/data/importer/PureApolloConfigTest.java, apollo-client-config-data/src/test/java/com/ctrip/framework/apollo/config/data/importer/PureApolloConfigIsolationTest.java
PureApolloConfigTest saves and restores the original env and spring.profiles.active properties and reinitializes Foundation. The new isolation tests check cleanup when those properties are set or unset, including restoration of Foundation’s cached environment.
Integration test environment lifecycle
apollo-client-config-data/src/test/java/com/ctrip/framework/apollo/config/data/integration/ConfigDataIntegrationTest.java
The test environment changes from local to dev. Setup and teardown reinitialize Foundation after setting and restoring test properties.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Suggested reviewers: shalk

Merge Risk: ⚪ Minimal · up to 8985b

No merge-blocking risk is identified; the test isolation change is ready for normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: isolating environment and cached state in config-data tests.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused test-only changes address the state leak with restoration regressions and no identified blocking issues.

No open issues 🎉

What changed in this PR

Fixes order-dependent ConfigData tests by isolating system properties and refreshing Foundation’s cached environment, without changing production behavior.

Changes:

  • Preserve and restore environment and profile properties.
  • Run MockWebServer integration tests explicitly in dev mode.
  • Add regression tests for existing and unset properties.
File Description
apollo-client-config-data/​src/​test/​java/​com/​ctrip/​framework/​apollo/​config/​data/​integration/​ConfigDataIntegrationTest.java Uses dev mode and refreshes Foundation during setup and cleanup.
apollo-client-config-data/​src/​test/​java/​com/​ctrip/​framework/​apollo/​config/​data/​importer/​PureApolloConfigTest.java Restores original properties and refreshes cached environment state.
apollo-client-config-data/​src/​test/​java/​com/​ctrip/​framework/​apollo/​config/​data/​importer/​PureApolloConfigIsolationTest.java Verifies property and cached-environment restoration.

Review effort: Balanced

@codecov

codecov Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.55%. Comparing base (d4b76f8) to head (5682d60).
⚠️ Report is 32 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #148      +/-   ##
============================================
+ Coverage     68.68%   71.55%   +2.87%     
- Complexity     1503     1667     +164     
============================================
  Files           212      225      +13     
  Lines          6396     6739     +343     
  Branches        647      688      +41     
============================================
+ Hits           4393     4822     +429     
+ Misses         1673     1562     -111     
- Partials        330      355      +25     

☔ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8985b7f2e1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@nobodyiam
nobodyiam force-pushed the codex/fix-config-data-test-isolation branch from 8985b7f to cae9e78 Compare October 17, 2026 02:14
@nobodyiam nobodyiam changed the title test(config-data): isolate Foundation environment state test(config-data): isolate environment and cache state Oct 17, 2026
@nobodyiam
nobodyiam force-pushed the codex/fix-config-data-test-isolation branch from cae9e78 to 5682d60 Compare October 17, 2026 02:24
@nobodyiam
nobodyiam merged commit 4b7d9dd into apolloconfig:main Oct 17, 2026
19 checks passed
@nobodyiam
nobodyiam deleted the codex/fix-config-data-test-isolation branch October 17, 2026 02:27
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants