From ccba12aa7228aa658aa31d20baf18b6b6cfa82be Mon Sep 17 00:00:00 2001 From: 317787106 <317787106@qq.com> Date: Tue, 13 Oct 2026 10:09:54 +0800 Subject: [PATCH 1/3] test(framework): await reward calculation before mutating store --- .../org/tron/core/services/ComputeRewardTest.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/framework/src/test/java/org/tron/core/services/ComputeRewardTest.java b/framework/src/test/java/org/tron/core/services/ComputeRewardTest.java index a1bffd5bf1f..0e5dbec1776 100644 --- a/framework/src/test/java/org/tron/core/services/ComputeRewardTest.java +++ b/framework/src/test/java/org/tron/core/services/ComputeRewardTest.java @@ -10,7 +10,9 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; @@ -248,8 +250,15 @@ private void setUp() { } @Test - public void query() { + public void query() throws InterruptedException { Assert.assertEquals(3189, mortgageService.queryReward(OWNER_ADDRESS)); + // queryReward() can return before the background Merkle-root calculation finishes. + // Wait for it before modifying or closing the store used by that calculation. + ExecutorService rewardExecutor = ReflectUtils.getFieldValue(rewardViCalService, "es"); + rewardExecutor.shutdown(); + Assert.assertTrue("Reward calculation did not terminate before modifying its store", + rewardExecutor.awaitTermination(10, TimeUnit.SECONDS)); + // mock root is error rewardViStore.put("test".getBytes(), "test".getBytes()); ReflectUtils.invokeMethod(rewardViCalService,"maybeRun"); From f312a2b4240f02c374253e027fadfcf2bc17ed40 Mon Sep 17 00:00:00 2001 From: 317787106 <317787106@qq.com> Date: Tue, 13 Oct 2026 11:48:18 +0800 Subject: [PATCH 2/3] use shutdownNow to replace shutdown in ComputeRewardTest.query --- .../src/test/java/org/tron/core/services/ComputeRewardTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/test/java/org/tron/core/services/ComputeRewardTest.java b/framework/src/test/java/org/tron/core/services/ComputeRewardTest.java index 0e5dbec1776..66e312c0a73 100644 --- a/framework/src/test/java/org/tron/core/services/ComputeRewardTest.java +++ b/framework/src/test/java/org/tron/core/services/ComputeRewardTest.java @@ -255,7 +255,7 @@ public void query() throws InterruptedException { // queryReward() can return before the background Merkle-root calculation finishes. // Wait for it before modifying or closing the store used by that calculation. ExecutorService rewardExecutor = ReflectUtils.getFieldValue(rewardViCalService, "es"); - rewardExecutor.shutdown(); + rewardExecutor.shutdownNow(); Assert.assertTrue("Reward calculation did not terminate before modifying its store", rewardExecutor.awaitTermination(10, TimeUnit.SECONDS)); From 800b8531ee12234c74f9ce2f82d7e8032543ae31 Mon Sep 17 00:00:00 2001 From: 317787106 <317787106@qq.com> Date: Tue, 13 Oct 2026 13:37:34 +0800 Subject: [PATCH 3/3] optimize ComputeRewardTest --- .../test/java/org/tron/core/services/ComputeRewardTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/framework/src/test/java/org/tron/core/services/ComputeRewardTest.java b/framework/src/test/java/org/tron/core/services/ComputeRewardTest.java index 66e312c0a73..9f69f69b9db 100644 --- a/framework/src/test/java/org/tron/core/services/ComputeRewardTest.java +++ b/framework/src/test/java/org/tron/core/services/ComputeRewardTest.java @@ -251,13 +251,14 @@ private void setUp() { @Test public void query() throws InterruptedException { - Assert.assertEquals(3189, mortgageService.queryReward(OWNER_ADDRESS)); + long reward = mortgageService.queryReward(OWNER_ADDRESS); // queryReward() can return before the background Merkle-root calculation finishes. - // Wait for it before modifying or closing the store used by that calculation. + // Wait before asserting or mutating the store; a failed assertion triggers teardown. ExecutorService rewardExecutor = ReflectUtils.getFieldValue(rewardViCalService, "es"); rewardExecutor.shutdownNow(); Assert.assertTrue("Reward calculation did not terminate before modifying its store", rewardExecutor.awaitTermination(10, TimeUnit.SECONDS)); + Assert.assertEquals(3189L, reward); // mock root is error rewardViStore.put("test".getBytes(), "test".getBytes());