refactor(config): merge test config files#6788
Conversation
| private static void setupStorage() { | ||
| StorageConfig sc = new StorageConfig(); | ||
| try { | ||
| setPrivateField(sc, "defaultDbOption", makeOverride(50)); |
There was a problem hiding this comment.
The reflection-based setPrivateField here bypasses the explicit @Setter(AccessLevel.NONE) on StorageConfig.defaultDbOption / defaultMDbOption / defaultLDbOption. Those annotations document an encapsulation contract — those fields are bound by ConfigBeanFactory and should be immutable post-binding — which this code silently breaks.
Three concrete downsides:
- Refactor-fragile: the field name is a string literal (
"defaultDbOption"). A future field rename via IDE will not touch this string, the project still compiles, and the test only fails at runtime withNoSuchFieldException. - Integration coverage lost: the deleted
config-test-storagetest.confexercised the fullConfigFactory → ConfigBeanFactory → @Setter(NONE) fieldspath. Bypassing it with reflection turns this into a unit test of utility functions; a future regression inConfigBeanFactorybinding of@Setter(NONE)fields would not be caught here. - Anti-pattern propagation: once
setPrivateFieldexists in the test tree, future tests are likely to copy it instead of pursuing cleaner solutions.
Suggested alternative — use ConfigFactory.parseString to exercise the real binding path with zero reflection and refactor-safety:
private static void setupStorage() {
Config cfg = ConfigFactory.parseString(
"storage.defaultDbOption.maxOpenFiles = 50\n" +
"storage.defaultMDbOption.maxOpenFiles = 500\n" +
"storage.defaultLDbOption.maxOpenFiles = 1000\n" +
"storage.properties = [\n" +
" { name = account, path = storage_directory_test, maxOpenFiles = 100, ... },\n" +
" { name = account-index, path = storage_directory_test, maxOpenFiles = 100, ... },\n" +
" { name = test_name, path = test_path, createIfMissing = false, blockSize = 2, ... }\n" +
"]")
.withFallback(ConfigFactory.defaultReference());
StorageConfig sc = StorageConfig.fromConfig(cfg);
storage.setDefaultDbOptions(sc);
storage.setPropertyMapFromBean(sc.getProperties());
}If @Setter(NONE) truly needs to be relaxed for testability, prefer @Setter(AccessLevel.PACKAGE) or an explicit @VisibleForTesting setter on StorageConfig — both are type-safe and document the intent.
There was a problem hiding this comment.
Good suggestion, use the real config string instead.
| public void get() { | ||
| Args.setParam(new String[] {"-c", TestConstants.TEST_CONF, "--keystore-factory"}, | ||
| TestConstants.NET_CONF); | ||
| Args.setParam(new String[] {"-c", TestConstants.TEST_CONF, "--keystore-factory"}, ""); |
There was a problem hiding this comment.
Passing "" as the second argument here is a code smell — Configuration.getByFileName explicitly rejects blank input with IllegalArgumentException("Configuration path is required!"), so an empty string is documented as invalid.
The test currently works because the -c TestConstants.TEST_CONF flag short-circuits the fallback path (in Args.setParam line ~166: isNoneBlank(shellConfFileName) ? shellConfFileName : confFileName). But this leaves a fragile dependency: if a future refactor removes the -c flag from this call site (e.g. switching to a different mechanism for selecting the test config), the empty-string second arg silently flows into getByFileName and the test fails with an opaque IllegalArgumentException.
Two safer options:
- Keep TestConstants.NET_CONF as the fallback constant (re-add it, semantically harmless since the body of the new
config-test.confcovers what NET_CONF used to point at). - Add an
Args.setParam(String[])overload that resolvesconfFileNameinternally (or acceptsOptional<String>) — eliminates the misleading placeholder pattern across the test suite.
Not blocking; just worth tracking before this pattern gets copy-pasted into other tests.
There was a problem hiding this comment.
Thanks for your suggestion, use the standard method instead although it doesn't matter much:
Args.setParam(new String[] {"--keystore-factory"}, TestConstants.TEST_CONF);
|
Follow-up observation, not blocking: although this PR deletes four redundant config files (-996 lines, well-deserved cleanup), the consolidated That's a real, but smaller, win. Worth being explicit in the PR description:
Otherwise reviewers (and future contributors) may expect the consolidation step alone to address the boilerplate problem, when in fact the boilerplate just got concentrated in one place. Concrete follow-up path, if someone wants to pursue it later: tests with narrow needs (e.g. |
| @@ -169,18 +169,7 @@ node { | |||
|
|
|||
|
|
|||
| seed.node = { | |||
There was a problem hiding this comment.
[NIT] docs still mention deleted test resource config-localtest.conf in implement-a-customized-actuator-{en/cn}.md
What does this PR do?
Consolidates test configuration files by deleting four redundant config files (
args-test.conf,config-test-index.conf,config-test-mainnet.conf,config-test-storagetest.conf) and standardizing tests to use a single sharedconfig-test.conf. Also renamesconfig-localtest.conftoconfig-shield.confto better reflect its purpose (shielded-transfer tests), and removes the hardcoded seed node list fromconfig-test.confsince unit tests have no need for P2P connectivity.Specifically:
config-localtest.conf→config-shield.confNET_CONF,MAINNET_CONF,LOCAL_CONF,STORAGE_CONF,INDEX_CONFfromTestConstants; addSHIELD_CONFTestConstants.TEST_CONForTestConstants.SHIELD_CONFinstead of bare string literalsconfig-test.conf; adjustArgsTestseed-node assertion from 11 → 0Why are these changes required?
The previous test suite maintained five separate
.conffiles that largely duplicated each other, making it hard to know which config to use for a new test and causing drift over time (e.g.,config-test-mainnet.confcontained mainnet genesis/seed data that is irrelevant and potentially misleading in a unit-test context). Centralizing to one default test config (config-test.conf) and one purpose-specific config (config-shield.conf) reduces maintenance overhead and eliminates accidental coupling to live-network parameters in tests.This PR has been tested by:
Extra details
StorageTestgains additional coverage to compensate for the removal ofconfig-test-storagetest.conf-dependent tests that were folded into the unified config.