You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by jx...@apache.org on 2023/04/17 16:59:50 UTC

[helix] branch master updated: Fix flaky integration test for helix-rest for TestClusterAccessor#testClusterFreeze. (#2451)

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 291ff047e Fix flaky integration test for helix-rest for TestClusterAccessor#testClusterFreeze. (#2451)
291ff047e is described below

commit 291ff047e93b661782025b307eb23c6193458696
Author: Zachary Pinto <zp...@uci.edu>
AuthorDate: Mon Apr 17 09:59:44 2023 -0700

    Fix flaky integration test for helix-rest for TestClusterAccessor#testClusterFreeze. (#2451)
    
    Fixing Flaky Integration Test TestClusterAccessor#testClusterFreeze
    
    This integration test is making a POST request to helix-rest to place cluster TestCluster_0 into CLUSTER_FREEZE status. It then attempts to verify that the following GET request for clusterStatus is in CLUSTER_FREEZE mode.
    
    Previously we were running this verification to check if the clusterStatus znode existed. This will not necessarily indicate that the pause event has been processed, as there could be an earlier event passed through the _managementEventPipeline that causes the znode to be created with clusterMode == NORMAL. This would lead us to make the GET request too early.
    
    Instead, we will verify that the clusterStatus znode has CLUSTER_FREEZE mode before we make the GET request. This will ensure that the pause event was already processed.
---
 .../helix/rest/server/TestClusterAccessor.java       | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java b/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java
index e53c72ab2..59cb51c9f 100644
--- a/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java
+++ b/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java
@@ -19,7 +19,6 @@ package org.apache.helix.rest.server;
  * under the License.
  */
 
-import com.fasterxml.jackson.core.JsonProcessingException;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -33,11 +32,11 @@ import javax.ws.rs.client.Entity;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.google.common.collect.ImmutableMap;
 import com.sun.research.ws.wadl.HTTPMethods;
-import org.apache.helix.AccessOption;
 import org.apache.helix.ConfigAccessor;
 import org.apache.helix.HelixDataAccessor;
 import org.apache.helix.PropertyKey;
@@ -54,6 +53,7 @@ import org.apache.helix.manager.zk.ZKUtil;
 import org.apache.helix.manager.zk.ZkBaseDataAccessor;
 import org.apache.helix.model.CloudConfig;
 import org.apache.helix.model.ClusterConfig;
+import org.apache.helix.model.ClusterStatus;
 import org.apache.helix.model.CustomizedStateConfig;
 import org.apache.helix.model.ExternalView;
 import org.apache.helix.model.IdealState;
@@ -1400,8 +1400,7 @@ public class TestClusterAccessor extends AbstractTestClass {
     // Set cluster pause mode
     ClusterManagementModeRequest request = ClusterManagementModeRequest.newBuilder()
         .withMode(ClusterManagementMode.Type.CLUSTER_FREEZE)
-        .withClusterName(cluster)
-        .build();
+        .withClusterName(cluster).build();
     String payload = OBJECT_MAPPER.writeValueAsString(request);
     post(endpoint, null, Entity.entity(payload, MediaType.APPLICATION_JSON_TYPE),
         Response.Status.OK.getStatusCode());
@@ -1411,12 +1410,15 @@ public class TestClusterAccessor extends AbstractTestClass {
     Assert.assertTrue(pauseSignal.isClusterPause());
     Assert.assertFalse(pauseSignal.getCancelPendingST());
 
-    // Wait until cluster status is persisted
-    TestHelper.verify(() -> dataAccessor.getBaseDataAccessor()
-            .exists(dataAccessor.keyBuilder().clusterStatus().getPath(), AccessOption.PERSISTENT),
-        TestHelper.WAIT_DURATION);
+    // Wait until cluster status is persisted and equals CLUSTER_FREEZE
+    TestHelper.verify(() -> {
+      ClusterStatus clusterStatus =
+          dataAccessor.getProperty(dataAccessor.keyBuilder().clusterStatus());
+      return clusterStatus != null
+          && clusterStatus.getManagementMode() == ClusterManagementMode.Type.CLUSTER_FREEZE;
+    }, TestHelper.WAIT_DURATION);
 
-    // Verify get cluster status
+    // Verify get cluster status GET request
     String body = get(endpoint, null, Response.Status.OK.getStatusCode(), true);
     Map<String, Object> responseMap = OBJECT_MAPPER.readerFor(Map.class).readValue(body);
     Assert.assertEquals(responseMap.get("mode"), ClusterManagementMode.Type.CLUSTER_FREEZE.name());