-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(framework): add dual DB engine coverage with flaky test fixes #6586
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
Changes from 1 commit
a9dfd5b
d57d110
7f71ab1
9283aca
abb52f6
d70c1c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,6 +134,18 @@ public static void setParam(final String[] args, final String confFileName) { | |
| initLocalWitnesses(config, cmd); | ||
|
Comment on lines
+127
to
137
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Step 2 ( This creates an ordering issue. It would be better to move the backup initialization logic that depends on Alternatively, if there is a better approach, it would be worth considering. That said, this change would impact existing tests related to
out of Suggested adjustment: // Insert into `setParam` AFTER Step 4
// Move out from `applyConfigParams`
initBackupProperty(config);
if (Constant.ROCKSDB.equalsIgnoreCase(
CommonParameter.getInstance().getStorage().getDbEngine())) {
initRocksDbBackupProperty(config);
initRocksDbSettings(config);
}
// Move out from `applyConfigParams`
logConfig(); // log final effective configuration
// Insert into `setParam` BEFORE Step 5It would also be helpful to add tests to verify that, on ARM64, even if
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. The real issue is that Fixed in d70c1c4 — removed the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. “Unconditionally reading and parsing configuration values into memory” is a great approach—simpler and more elegant than the modification I suggested. |
||
| } | ||
|
|
||
| /** | ||
| * Validate final configuration after all sources (defaults, config, CLI) are applied. | ||
| */ | ||
| public static void validateConfig() { | ||
| if (Arch.isArm64() && !"ROCKSDB".equals(PARAMETER.storage.getDbEngine())) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! Will fix to use |
||
| throw new TronError( | ||
| "ARM64 architecture only supports RocksDB. Current engine: " | ||
| + PARAMETER.storage.getDbEngine(), | ||
| TronError.ErrCode.PARAMETER_INIT); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Apply parameters from config file. | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ public static void main(String[] args) { | |
| ExitManager.initExceptionHandler(); | ||
| checkJdkVersion(); | ||
| Args.setParam(args, "config.conf"); | ||
| Args.validateConfig(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch on all three points! Fixed in abb52f6:
|
||
| CommonParameter parameter = Args.getInstance(); | ||
|
|
||
| LogService.load(parameter.getLogbackPath()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package org.tron.common; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.rules.TemporaryFolder; | ||
| import org.tron.common.application.Application; | ||
| import org.tron.common.application.ApplicationFactory; | ||
| import org.tron.common.application.TronApplicationContext; | ||
| import org.tron.core.ChainBaseManager; | ||
| import org.tron.core.config.DefaultConfig; | ||
| import org.tron.core.config.args.Args; | ||
| import org.tron.core.db.Manager; | ||
|
|
||
| /** | ||
| * Base class for tests that need a fresh Spring context per test method. | ||
| * | ||
| * Each @Test method gets its own TronApplicationContext, created in @Before | ||
| * and destroyed in @After, ensuring full isolation between tests. | ||
| * | ||
| * Subclasses can customize behavior by overriding hook methods: | ||
| * extraArgs() — additional CLI args (e.g. "--debug") | ||
| * configFile() — config file (default: config-test.conf) | ||
| * beforeContext() — runs after Args.setParam, before Spring context creation | ||
| * afterInit() — runs after Spring context is ready (e.g. get extra beans) | ||
| * beforeDestroy() — runs before context shutdown (e.g. close resources) | ||
| * | ||
| * Use this when: | ||
| * - methods modify database state that would affect other methods | ||
| * - methods need different CommonParameter settings (e.g. setP2pDisable) | ||
| * - methods need beforeContext() to configure state before Spring starts | ||
| * | ||
| * If methods are read-only and don't interfere with each other, use BaseTest instead. | ||
| * Tests that don't need Spring (e.g. pure unit tests) should NOT extend either base class. | ||
| */ | ||
| @Slf4j | ||
| public abstract class BaseMethodTest { | ||
|
|
||
| @Rule | ||
| public final TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
|
|
||
| protected TronApplicationContext context; | ||
| protected Application appT; | ||
| protected Manager dbManager; | ||
| protected ChainBaseManager chainBaseManager; | ||
|
|
||
| protected String[] extraArgs() { | ||
| return new String[0]; | ||
| } | ||
|
|
||
| protected String configFile() { | ||
| return TestConstants.TEST_CONF; | ||
| } | ||
|
|
||
| @Before | ||
| public final void initContext() throws IOException { | ||
| String[] baseArgs = new String[]{ | ||
| "--output-directory", temporaryFolder.newFolder().toString()}; | ||
| String[] allArgs = mergeArgs(baseArgs, extraArgs()); | ||
| Args.setParam(allArgs, configFile()); | ||
| beforeContext(); | ||
| context = new TronApplicationContext(DefaultConfig.class); | ||
| appT = ApplicationFactory.create(context); | ||
| dbManager = context.getBean(Manager.class); | ||
| chainBaseManager = context.getBean(ChainBaseManager.class); | ||
| afterInit(); | ||
| } | ||
|
|
||
| protected void beforeContext() { | ||
| } | ||
|
|
||
| protected void afterInit() { | ||
| } | ||
|
|
||
| @After | ||
| public final void destroyContext() { | ||
| beforeDestroy(); | ||
| if (appT != null) { | ||
| appT.shutdown(); | ||
| } | ||
| if (context != null) { | ||
| context.close(); | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When Specifically, public final void destroyContext() {
beforeDestroy();
if (appT != null) {
appT.shutdown(); // first shutdown
}
if (context != null) {
context.close(); // triggers second shutdown
}
Args.clearParam();
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! Fixed in abb52f6 — removed the explicit |
||
| Args.clearParam(); | ||
| } | ||
|
|
||
| protected void beforeDestroy() { | ||
| } | ||
|
|
||
| private static String[] mergeArgs(String[] base, String[] extra) { | ||
| String[] result = Arrays.copyOf(base, base.length + extra.length); | ||
| System.arraycopy(extra, 0, result, base.length, extra.length); | ||
| return result; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,39 @@ | ||
| package org.tron.common; | ||
|
|
||
| import static org.junit.Assume.assumeFalse; | ||
|
|
||
| import org.tron.common.arch.Arch; | ||
|
|
||
| /** | ||
| * Centralized test environment constants and utilities. | ||
| * | ||
| * <h3>DB engine override for dual-engine testing</h3> | ||
| * Gradle tasks ({@code test} on ARM64, {@code testWithRocksDb}) set the JVM system property | ||
| * {@code -Dstorage.db.engine=ROCKSDB}. Because test config files are loaded from the classpath | ||
| * via {@code ConfigFactory.load(fileName)}, Typesafe Config automatically merges system | ||
| * properties with higher priority than the config file values. This means the config's | ||
| * {@code storage.db.engine = "LEVELDB"} is overridden transparently, without any code changes | ||
| * in individual tests. | ||
| * | ||
| * <p><b>IMPORTANT:</b> Config files MUST be classpath resources (in {@code src/test/resources/}), | ||
| * NOT standalone files in the working directory. If a config file exists on disk, | ||
| * {@code Configuration.getByFileName} falls back to {@code ConfigFactory.parseFile()}, | ||
| * which does NOT merge system properties, and the engine override will silently fail. | ||
| */ | ||
| public class TestConstants { | ||
|
|
||
| public static final String TEST_CONF = "config-test.conf"; | ||
| public static final String NET_CONF = "config.conf"; | ||
| public static final String MAINNET_CONF = "config-test-mainnet.conf"; | ||
| public static final String DBBACKUP_CONF = "config-test-dbbackup.conf"; | ||
| public static final String LOCAL_CONF = "config-localtest.conf"; | ||
| public static final String STORAGE_CONF = "config-test-storagetest.conf"; | ||
| public static final String INDEX_CONF = "config-test-index.conf"; | ||
|
|
||
| /** | ||
| * Skips the current test on ARM64 where LevelDB JNI is unavailable. | ||
| */ | ||
| public static void assumeLevelDbAvailable() { | ||
| assumeFalse("LevelDB JNI unavailable on ARM64", Arch.isArm64()); | ||
| } | ||
| } |
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.
This change and
validateConfigintroduce a regression: on ARM64, starting the node with the defaultconfig.conf(wheredb.engineis set toLEVELDB) now results in a startup failure.The issue can be reproduced as follows:
$ ./gradlew :framework:buildFullNodeJar ….. Building for architecture: aarch64, Java version: 17 ….. $ java -jar framework/build/libs/FullNode.jar $ tail -f logs/tron.log ….. 15:17:21.876 ERROR [main] [Exit](ExitManager.java:49) Shutting down with code: PARAMETER_INIT(1), reason: ARM64 architecture only supports RocksDB. Current engine: LEVELDBThere 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.
Agreed. I've opened an issue to continue the discussion: #6587
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.
I believe fail-fast is the correct behavior here. If a user runs on ARM64 with
db.engine=LEVELDB, the node should refuse to start with a clear error message, rather than silently falling back to RocksDB or deferring the failure to runtime.The principle is: no hidden behavior. If you're running on ARM64, you must explicitly configure a supported engine. A silent fallback would mask a misconfiguration and could lead to confusion later (e.g., user expects LevelDB but data is actually stored in RocksDB).
That said, I understand the concern about the default
config.confshipping withLEVELDB. This is really a config-level issue — the default config should either be platform-aware or the documentation should clearly state that ARM64 users need to setdb.engine=ROCKSDB. Happy to discuss further in #6587.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.
To add more context: the whole point of this series of changes is to eliminate silent behaviors in FullNode. Silently swapping the DB engine in production is exactly the kind of hidden behavior we're trying to remove — it should be strictly prohibited.
If an ARM64 node has
db.engine=LEVELDBinconfig.conf, that's a configuration management problem, not something the application should paper over at runtime. Mixing config-management concerns into production code leads to harder-to-debug issues and undermines the principle of explicit configuration.The correct fix belongs in the deployment/config layer — ARM64 environments should ship with the right
config.conffrom the start.