From baa3b699b2f2b2dc2f8e229df03063eccd50fd34 Mon Sep 17 00:00:00 2001 From: Hu Zongtang Date: Tue, 26 May 2020 20:05:51 +0800 Subject: [PATCH] (fix#411).TestLeaderStopAndReElectWithPriority unittest run failure. (#458) * (fix#411).TestLeaderStopAndReElectWithPriority unittest run failure. --- .../com/alipay/sofa/jraft/core/NodeTest.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/jraft-core/src/test/java/com/alipay/sofa/jraft/core/NodeTest.java b/jraft-core/src/test/java/com/alipay/sofa/jraft/core/NodeTest.java index 2198a6e0c..0cf6f71e9 100644 --- a/jraft-core/src/test/java/com/alipay/sofa/jraft/core/NodeTest.java +++ b/jraft-core/src/test/java/com/alipay/sofa/jraft/core/NodeTest.java @@ -1048,8 +1048,22 @@ public void testLeaderStopAndReElectWithPriority() throws Exception { leader = cluster.getLeader(); assertNotNull(leader); - assertEquals(60, leader.getNodeId().getPeerId().getPriority()); - assertEquals(100, leader.getNodeTargetPriority()); + + // get current leader priority value + int leaderPriority = leader.getNodeId().getPeerId().getPriority(); + + // get current leader log size + int peer1LogSize = cluster.getFsmByPeer(peers.get(1)).getLogs().size(); + int peer2LogSize = cluster.getFsmByPeer(peers.get(2)).getLogs().size(); + + // if the leader is lower priority value + if (leaderPriority == 10) { + // we just compare the two peers' log size value; + assertTrue(peer2LogSize > peer1LogSize); + } else { + assertEquals(60, leader.getNodeId().getPeerId().getPriority()); + assertEquals(100, leader.getNodeTargetPriority()); + } cluster.stopAll(); }