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..9f69f69b9db 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,16 @@ private void setUp() { } @Test - public void query() { - Assert.assertEquals(3189, mortgageService.queryReward(OWNER_ADDRESS)); + public void query() throws InterruptedException { + long reward = mortgageService.queryReward(OWNER_ADDRESS); + // queryReward() can return before the background Merkle-root calculation finishes. + // 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()); ReflectUtils.invokeMethod(rewardViCalService,"maybeRun");