File tree Expand file tree Collapse file tree
framework/src/test/java/org/tron/core/services Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010import java .util .List ;
1111import java .util .Map ;
1212import java .util .concurrent .ExecutionException ;
13+ import java .util .concurrent .ExecutorService ;
1314import java .util .concurrent .Future ;
15+ import java .util .concurrent .TimeUnit ;
1416import org .junit .Assert ;
1517import org .junit .Rule ;
1618import 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" );
You can’t perform that action at this time.
0 commit comments