Repository navigation
fix(test): isolate cross-test state leaks and stabilize flaky suites #6974
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
Merged
kuny0707
merged 9 commits into
tronprotocol:release_v4.8.3
from
warku123:fix/unit-test-cleanup-release
Sep 22, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3a99002
test: isolate shared VM and peer state between tests
warku123 1480700
test: clean up backup server test resources
warku123 2221701
test: scope shielded consensus lifecycle and isolate transaction handler
warku123 b028046
test: randomize fixed ports and release native queues
warku123 7aeba23
test: fix VM assertion order and restore shielded flag
warku123 9c8dac0
test: restore AllowTvmLondon flag in AllowTvmCompatibleEvmTest teardown
warku123 7460d13
test: await peer executor termination and install mock pool before fi…
warku123 9f4e65d
test: pin resetter field coverage and document vm rule boundaries
warku123 32e43ad
test: skip synthetic fields in resetter pin test
warku123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package org.tron.common; | ||
|
|
||
| import java.lang.reflect.Field; | ||
| import org.junit.rules.ExternalResource; | ||
| import org.tron.common.parameter.CommonParameter; | ||
| import org.tron.core.vm.config.ConfigLoader; | ||
| import org.tron.core.vm.config.VMConfig; | ||
|
|
||
| /** | ||
| * Restores VM flags after each test, including failed setup and assertion paths. | ||
| * | ||
| * <p>Snapshotting enumerates {@link VMConfig.Snapshot} fields reflectively, so any static flag | ||
| * not mirrored there is outside this rule's protection: when adding a static flag to | ||
| * {@link VMConfig} or {@link ConfigLoader}, it must also be mirrored into | ||
| * {@code VMConfig.Snapshot} (before/after save and restore) or it will leak across tests. | ||
| * | ||
| * <p>This is a method-level rule: the baseline is captured before every test method, so global | ||
| * flags written from class-level {@code @BeforeClass} code are not covered — such classes must | ||
| * add their own {@code @AfterClass} to reset them manually (a leaked London hard-fork flag from | ||
| * class-level setup is an instance of exactly this gap). | ||
| */ | ||
| public class VMConfigRule extends ExternalResource { | ||
|
|
||
| private VMConfig.Snapshot savedSnapshot; | ||
| private boolean savedLoaderDisabled; | ||
| private boolean savedHardFork; | ||
| private boolean savedTrace; | ||
|
|
||
| @Override | ||
| protected void before() throws Exception { | ||
| Field global = VMConfig.class.getDeclaredField("globalSnapshot"); | ||
| global.setAccessible(true); | ||
| VMConfig.Snapshot current = (VMConfig.Snapshot) global.get(null); | ||
| savedSnapshot = new VMConfig.Snapshot(); | ||
| // init* methods mutate the snapshot in place, so saving only its reference is insufficient. | ||
| for (Field flag : VMConfig.Snapshot.class.getFields()) { | ||
| flag.set(savedSnapshot, flag.get(current)); | ||
| } | ||
| savedLoaderDisabled = ConfigLoader.disable; | ||
| savedHardFork = CommonParameter.ENERGY_LIMIT_HARD_FORK; | ||
| savedTrace = VMConfig.vmTrace(); | ||
| VMConfig.clearLocalSnapshot(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void after() { | ||
| VMConfig.setGlobalSnapshot(savedSnapshot); | ||
| ConfigLoader.disable = savedLoaderDisabled; | ||
| VMConfig.initVmHardFork(savedHardFork); | ||
| VMConfig.setVmTrace(savedTrace); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[NIT] VMConfigRule covers method scope only; class-scope VM flag leaks still rely on manual afterClass lists
As a @rule (method-level), this does not wrap @BeforeClass/static blocks. AllowTvmCompatibleEvmTest sets 6 VM flags in @BeforeClass and still restores them via a hand-maintained @afterclass list — and the missing initAllowTvmLondon(0) entry fixed in this very PR is proof that the manual-list mechanism keeps leaking. The 13 VMTestBase subclasses inherit the rule, but any class-scope flag mutation remains uncovered.
Suggestion: add a @ClassRule-level VM snapshot restore on VMTestBase (or BaseTest/BaseMethodTest) so @BeforeClass leaks are covered automatically; alternatively, state explicitly in this class's javadoc that class-scope mutations are not covered and document the recommended pattern. Fine as a follow-up, does not block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documented in the
VMConfigRulejavadoc: the Snapshot enumeration blind spot (static flags added toVMConfig/ConfigLoadermust be mirrored intoVMConfig.Snapshotor they leak across tests) and the method-level-rule boundary (@BeforeClasswrites are outside the baseline and need a manual@AfterClassreset — the missed London flag was exactly this gap, fixed in 9c8dac0). A@ClassRule-based variant that would cover class-level setup mechanically is noted as a follow-up; kept out of this PR to avoid churning shared test infra further.Pushed as 9f4e65d.