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

tanxinyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new e2c705aa898 [IOTDB-6061] Fix the instability failure caused by 
initServer in IoTConsensus UT not binding to the corresponding port (#12674)
e2c705aa898 is described below

commit e2c705aa8981230d9c7c5f12b8504115876710e4
Author: Xiangpeng Hu <[email protected]>
AuthorDate: Thu Jun 6 14:13:09 2024 +0800

    [IOTDB-6061] Fix the instability failure caused by initServer in 
IoTConsensus UT not binding to the corresponding port (#12674)
    
    * fix concurrent
    
    * fix concurrent
---
 .../apache/iotdb/consensus/iot/ReplicateTest.java  | 51 +++++++++++++---------
 1 file changed, 31 insertions(+), 20 deletions(-)

diff --git 
a/iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/iot/ReplicateTest.java
 
b/iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/iot/ReplicateTest.java
index 6e2326dd546..8072ab10066 100644
--- 
a/iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/iot/ReplicateTest.java
+++ 
b/iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/iot/ReplicateTest.java
@@ -100,26 +100,37 @@ public class ReplicateTest {
 
   private void initServer() throws IOException {
     Assume.assumeTrue(checkPortAvailable());
-    for (int i = 0; i < peers.size(); i++) {
-      int finalI = i;
-      servers.add(
-          (IoTConsensus)
-              ConsensusFactory.getConsensusImpl(
-                      ConsensusFactory.IOT_CONSENSUS,
-                      ConsensusConfig.newBuilder()
-                          .setThisNodeId(peers.get(i).getNodeId())
-                          .setThisNode(peers.get(i).getEndpoint())
-                          .setStorageDir(peersStorage.get(i).getAbsolutePath())
-                          
.setConsensusGroupType(TConsensusGroupType.DataRegion)
-                          .build(),
-                      groupId -> stateMachines.get(finalI))
-                  .orElseThrow(
-                      () ->
-                          new IllegalArgumentException(
-                              String.format(
-                                  ConsensusFactory.CONSTRUCT_FAILED_MSG,
-                                  ConsensusFactory.IOT_CONSENSUS))));
-      servers.get(i).start();
+    try {
+      for (int i = 0; i < peers.size(); i++) {
+        int finalI = i;
+        servers.add(
+            (IoTConsensus)
+                ConsensusFactory.getConsensusImpl(
+                        ConsensusFactory.IOT_CONSENSUS,
+                        ConsensusConfig.newBuilder()
+                            .setThisNodeId(peers.get(i).getNodeId())
+                            .setThisNode(peers.get(i).getEndpoint())
+                            
.setStorageDir(peersStorage.get(i).getAbsolutePath())
+                            
.setConsensusGroupType(TConsensusGroupType.DataRegion)
+                            .build(),
+                        groupId -> stateMachines.get(finalI))
+                    .orElseThrow(
+                        () ->
+                            new IllegalArgumentException(
+                                String.format(
+                                    ConsensusFactory.CONSTRUCT_FAILED_MSG,
+                                    ConsensusFactory.IOT_CONSENSUS))));
+        servers.get(i).start();
+      }
+    } catch (IOException e) {
+      if (e.getCause() instanceof StartupException) {
+        // just succeed when can not bind socket
+        logger.info("Can not start IoTConsensus because", e);
+        Assume.assumeTrue(false);
+      } else {
+        logger.error("Failed because", e);
+        Assert.fail("Failed because " + e.getMessage());
+      }
     }
   }
 

Reply via email to