This is an automated email from the ASF dual-hosted git repository.

szetszwo pushed a commit to branch branch-2_tmp
in repository https://gitbox.apache.org/repos/asf/ratis.git

commit beb6a5dfd3a59cbc78103490917e7ad473baa6f4
Author: Kaijie Chen <[email protected]>
AuthorDate: Sat Feb 25 04:04:01 2023 +0800

    RATIS-1791. Intermittent failure in ServerRestartTests#testRestartFollower 
(#827)
    
    (cherry picked from commit 3a19630a8fe17e055f820b712450123201641421)
---
 .../test/java/org/apache/ratis/server/ServerRestartTests.java  | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git 
a/ratis-test/src/test/java/org/apache/ratis/server/ServerRestartTests.java 
b/ratis-test/src/test/java/org/apache/ratis/server/ServerRestartTests.java
index 2c0e18167..31e673099 100644
--- a/ratis-test/src/test/java/org/apache/ratis/server/ServerRestartTests.java
+++ b/ratis-test/src/test/java/org/apache/ratis/server/ServerRestartTests.java
@@ -119,18 +119,22 @@ public abstract class ServerRestartTests<CLUSTER extends 
MiniRaftCluster>
     final RaftLog followerLog = follower.getRaftLog();
     final long followerLastIndex = 
followerLog.getLastEntryTermIndex().getIndex();
     Assert.assertTrue(followerLastIndex >= leaderLastIndex);
+    final long leaderFinalIndex = 
cluster.getLeader().getRaftLog().getLastEntryTermIndex().getIndex();
+    Assert.assertEquals(leaderFinalIndex, followerLastIndex);
 
     final File followerOpenLogFile = getOpenLogFile(follower);
     final File leaderOpenLogFile = 
getOpenLogFile(cluster.getDivision(leaderId));
 
     // shutdown all servers
-    for(RaftServer s : cluster.getServers()) {
-      s.close();
+    // shutdown followers first, so there won't be any new leader elected
+    for (RaftServer.Division d : cluster.getFollowers()) {
+      d.close();
     }
+    cluster.getDivision(leaderId).close();
 
     // truncate log and
     assertTruncatedLog(followerId, followerOpenLogFile, followerLastIndex, 
cluster);
-    assertTruncatedLog(leaderId, leaderOpenLogFile, leaderLastIndex, cluster);
+    assertTruncatedLog(leaderId, leaderOpenLogFile, leaderFinalIndex, cluster);
 
     // restart and write something.
     cluster.restart(false);

Reply via email to