Skip to content

Commit e1ffb1c

Browse files
authored
test(framework): await reward calculation before mutating store (#7025)
1 parent 9ff3596 commit e1ffb1c

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎framework/src/test/java/org/tron/core/services/ComputeRewardTest.java‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import java.util.List;
1111
import java.util.Map;
1212
import java.util.concurrent.ExecutionException;
13+
import java.util.concurrent.ExecutorService;
1314
import java.util.concurrent.Future;
15+
import java.util.concurrent.TimeUnit;
1416
import org.junit.Assert;
1517
import org.junit.Rule;
1618
import org.junit.Test;
@@ -248,8 +250,16 @@ private void setUp() {
248250
}
249251

250252
@Test
251-
public void query() {
252-
Assert.assertEquals(3189, mortgageService.queryReward(OWNER_ADDRESS));
253+
public void query() throws InterruptedException {
254+
long reward = mortgageService.queryReward(OWNER_ADDRESS);
255+
// queryReward() can return before the background Merkle-root calculation finishes.
256+
// Wait before asserting or mutating the store; a failed assertion triggers teardown.
257+
ExecutorService rewardExecutor = ReflectUtils.getFieldValue(rewardViCalService, "es");
258+
rewardExecutor.shutdownNow();
259+
Assert.assertTrue("Reward calculation did not terminate before modifying its store",
260+
rewardExecutor.awaitTermination(10, TimeUnit.SECONDS));
261+
Assert.assertEquals(3189L, reward);
262+
253263
// mock root is error
254264
rewardViStore.put("test".getBytes(), "test".getBytes());
255265
ReflectUtils.invokeMethod(rewardViCalService,"maybeRun");

0 commit comments

Comments
 (0)