From ba07818848d44d492c1469297fb285e404cb4fdf Mon Sep 17 00:00:00 2001 From: wb Date: Mon, 23 Nov 2026 11:09:23 +0800 Subject: [PATCH] test(config): align dynamic reload coverage with peer-only parsing Resolve the semantic mismatch between #7113 and #7117. Keep peer reload independent of unrelated API configuration and retain recovery when a newer configuration follows a loading failure. Production behavior is unchanged. --- .../config/args/DynamicArgsReloadTest.java | 49 ++++++++++++++++--- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/framework/src/test/java/org/tron/core/config/args/DynamicArgsReloadTest.java b/framework/src/test/java/org/tron/core/config/args/DynamicArgsReloadTest.java index b0b47ad92df..87a5aa014ea 100644 --- a/framework/src/test/java/org/tron/core/config/args/DynamicArgsReloadTest.java +++ b/framework/src/test/java/org/tron/core/config/args/DynamicArgsReloadTest.java @@ -99,20 +99,49 @@ public void restoreConfiguration() { } @Test - public void retriesAfterInvalidApiSettings() throws Exception { - assertRecoversAfterInvalidConfig( + public void reloadsPeersDespiteInvalidApiSettings() throws Exception { + String[] invalidSettings = { "node.rpc.maxConcurrentCallsPerConnection = -1", + "node.rpc.maxConnectionIdleInMillis = -1", + "node.rpc.maxConnectionAgeInMillis = -1", "node.rpc.maxRstStream = -1", "node.rpc.maxRstStream = 2147483647", "node.rpc.secondsPerWindow = -1", "node.rpc.maxMessageSize = -1", "node.http.maxMessageSize = -1", - "node.jsonrpc.maxMessageSize = -1"); + "node.jsonrpc.maxMessageSize = -1", + "node.rpc.maxMessageSize = []" + }; + long editedTimestamp = initialTimestamp; + try (MockedStatic netService = mockStatic(TronNetService.class)) { + netService.when(TronNetService::getP2pConfig).thenReturn(p2pConfig); + for (int i = 0; i < invalidSettings.length; i++) { + String activeIp = "192.0.2." + (3 + 2 * i); + String passiveIp = "192.0.2." + (4 + 2 * i); + editedTimestamp = writeConfig(invalidSettings[i], activeIp, passiveIp, + editedTimestamp + 2000); + reloadTask.run(); + assertEquals(invalidSettings[i], editedTimestamp, lastModified()); + assertNodes(activeIp, passiveIp); + } + } + } + + @Test + public void retriesAfterMalformedPeers() throws Exception { + assertRecoversAfterInvalidConfig( + "node.active = [\"192.0.2.3:not-a-port\"]", + "node.passive = [\"192.0.2.4:not-a-port\"]"); } @Test public void retriesAfterWrongConfigType() throws Exception { - assertRecoversAfterInvalidConfig("node.rpc.maxMessageSize = []"); + assertRecoversAfterInvalidConfig("node.active = 123", "node.passive = 123"); + } + + @Test + public void retriesAfterMalformedConfig() throws Exception { + assertRecoversAfterInvalidConfig("node.passive = ["); } @Test @@ -130,12 +159,16 @@ private void assertReloadsNewerFileAfterError(Error failure) throws Exception { long editedTimestamp = writeConfig("", "192.0.2.3", "192.0.2.4", initialTimestamp + 2000); try (MockedStatic netService = mockStatic(TronNetService.class)) { netService.when(TronNetService::getP2pConfig).thenReturn(p2pConfig); - try (MockedStatic nodeConfig = mockStatic(NodeConfig.class)) { - nodeConfig.when(() -> NodeConfig.fromConfig(any())).thenThrow(failure); + try (MockedStatic configuration = mockStatic(Configuration.class)) { + configuration.when(() -> Configuration.getByFileName(configFile.toString())) + .thenThrow(failure); + reloadTask.run(); + assertEquals(editedTimestamp, lastModified()); + assertNodes("192.0.2.1", "192.0.2.2"); + reloadTask.run(); + configuration.verify(() -> Configuration.getByFileName(configFile.toString()), times(1)); } - assertEquals(editedTimestamp, lastModified()); - assertNodes("192.0.2.1", "192.0.2.2"); long newerTimestamp = writeConfig("", "192.0.2.5", "192.0.2.6", editedTimestamp + 2000); reloadTask.run();