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

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


The following commit(s) were added to refs/heads/master by this push:
     new 0ade21e4b Fix unstable test of TestInstanceOperation
0ade21e4b is described below

commit 0ade21e4b30b667ee99ebc1603af1d7380289e19
Author: Junkai Xue <[email protected]>
AuthorDate: Tue Feb 24 19:19:49 2026 -0800

    Fix unstable test of TestInstanceOperation
    
      1. Fixed testEvacuateWithDisabledPartition (#2906): Changed hardcoded 
5000ms to TIMEOUT (10000ms)
      2. Fixed validateRoutingTablesInstance method: Added polling mechanism 
with TIMEOUT for all callers:
        - testNodeSwapWithSwapOutInstanceOffline (#2874)
        - testNodeSwapDisableAndReenable (#2997)
        - testNodeSwapSwapInNodeNoInstanceOperation (#3001)
        - And 10+ other tests that use this method
---
 .../rebalancer/TestInstanceOperation.java          | 56 +++++++++++++++++-----
 1 file changed, 45 insertions(+), 11 deletions(-)

diff --git 
a/helix-core/src/test/java/org/apache/helix/integration/rebalancer/TestInstanceOperation.java
 
b/helix-core/src/test/java/org/apache/helix/integration/rebalancer/TestInstanceOperation.java
index 83b7c0192..5ea4ae7ed 100644
--- 
a/helix-core/src/test/java/org/apache/helix/integration/rebalancer/TestInstanceOperation.java
+++ 
b/helix-core/src/test/java/org/apache/helix/integration/rebalancer/TestInstanceOperation.java
@@ -1573,7 +1573,7 @@ public class TestInstanceOperation extends ZkTestBase {
         }
       }
       return true;
-    }, 5000);
+    }, TIMEOUT);
 
     // Assert node received downward state transitions and no upward 
transitions
     
Assert.assertEquals(stateTransitionCountStateModelFactory.getUpwardStateTransitionCounter(),
@@ -1833,20 +1833,54 @@ public class TestInstanceOperation extends ZkTestBase {
 
   private void validateRoutingTablesInstance(Map<String, ExternalView> evs, 
String instanceName,
       boolean shouldContain) {
+    validateRoutingTablesInstance(evs, instanceName, shouldContain, TIMEOUT);
+  }
+
+  private void validateRoutingTablesInstance(Map<String, ExternalView> evs, 
String instanceName,
+      boolean shouldContain, long timeout) {
     RoutingTableProvider[] routingTableProviders =
         new RoutingTableProvider[]{_routingTableProviderDefault, 
_routingTableProviderEV, _routingTableProviderCS};
-    getResourcePartitionStateOnInstance(evs, instanceName).forEach((resource, 
partitions) -> {
-      partitions.forEach((partition, state) -> {
-        Arrays.stream(routingTableProviders).forEach(rtp -> 
Assert.assertEquals(
-            getInstanceNames(rtp.getInstancesForResource(resource, partition, 
state)).contains(
-                instanceName), shouldContain));
+
+    // Get partitions that should be checked
+    Map<String, Map<String, String>> resourcePartitionStateOnInstance = 
getResourcePartitionStateOnInstance(evs, instanceName);
+
+    // If there are no partitions to check, just verify the instance config 
presence
+    if (resourcePartitionStateOnInstance.isEmpty()) {
+      Arrays.stream(routingTableProviders).forEach(rtp -> {
+        
Assert.assertEquals(getInstanceNames(rtp.getInstanceConfigs()).contains(instanceName),
+            shouldContain);
       });
-    });
+      return;
+    }
+
+    // Use polling to wait for routing table to update
+    verifier(() -> {
+      try {
+        for (String resource : resourcePartitionStateOnInstance.keySet()) {
+          Map<String, String> partitions = 
resourcePartitionStateOnInstance.get(resource);
+          for (String partition : partitions.keySet()) {
+            String state = partitions.get(partition);
+            for (RoutingTableProvider rtp : routingTableProviders) {
+              boolean contains = 
getInstanceNames(rtp.getInstancesForResource(resource, partition, state))
+                  .contains(instanceName);
+              if (contains != shouldContain) {
+                return false;
+              }
+            }
+          }
+        }
 
-    Arrays.stream(routingTableProviders).forEach(rtp -> {
-      
Assert.assertEquals(getInstanceNames(rtp.getInstanceConfigs()).contains(instanceName),
-          shouldContain);
-    });
+        for (RoutingTableProvider rtp : routingTableProviders) {
+          boolean contains = 
getInstanceNames(rtp.getInstanceConfigs()).contains(instanceName);
+          if (contains != shouldContain) {
+            return false;
+          }
+        }
+        return true;
+      } catch (Exception e) {
+        return false;
+      }
+    }, timeout);
   }
 
   private void validateEVCorrect(ExternalView actual, ExternalView original,

Reply via email to