You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by hz...@apache.org on 2020/08/21 22:01:59 UTC

[helix] branch master updated: Fix flaky test testMBeanApplicationName (#1298)

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

hzlu 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 57d6a21  Fix flaky test testMBeanApplicationName (#1298)
57d6a21 is described below

commit 57d6a21f7b56bbdf95fd4db25844efa0d805e027
Author: Huizhi Lu <ih...@gmail.com>
AuthorDate: Fri Aug 21 15:01:50 2020 -0700

    Fix flaky test testMBeanApplicationName (#1298)
    
    The test intermittently fails on GitHub CI because default namespace may not be reflected to mbean server yet, if there is a race condition between test and mbean server and the default object name is missing. This PR fixes it by using TestHelper.verify() to check the result.
---
 .../rest/server/TestDefaultMonitoringMbeans.java   | 27 ++++++++--------------
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/helix-rest/src/test/java/org/apache/helix/rest/server/TestDefaultMonitoringMbeans.java b/helix-rest/src/test/java/org/apache/helix/rest/server/TestDefaultMonitoringMbeans.java
index 185c136..49dfee3 100644
--- a/helix-rest/src/test/java/org/apache/helix/rest/server/TestDefaultMonitoringMbeans.java
+++ b/helix-rest/src/test/java/org/apache/helix/rest/server/TestDefaultMonitoringMbeans.java
@@ -28,7 +28,6 @@ import javax.management.AttributeNotFoundException;
 import javax.management.InstanceNotFoundException;
 import javax.management.MBeanException;
 import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 import javax.management.ReflectionException;
 import javax.ws.rs.core.Response;
@@ -83,26 +82,20 @@ public class TestDefaultMonitoringMbeans extends AbstractTestClass {
   }
 
   @Test
-  public void testMBeanApplicationName()
-      throws MalformedObjectNameException {
+  public void testMBeanApplicationName() throws Exception {
     Set<String> namespaces =
         new HashSet<>(Arrays.asList(HelixRestNamespace.DEFAULT_NAMESPACE_NAME, TEST_NAMESPACE));
     MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
-    Set<ObjectName> objectNames =
-        mBeanServer.queryNames(new ObjectName(DEFAULT_METRIC_DOMAIN + ":*"), null);
 
-    Set<String> appNames = new HashSet<>();
-    for (ObjectName mBeanName : objectNames) {
-      appNames.add(mBeanName.getKeyProperty("type"));
-    }
-
-    Assert.assertEquals(appNames.size(), namespaces.size(), String
-        .format("appNames: %s does't have the same size as namespaces: %s.", appNames, namespaces));
+    TestHelper.verify(() -> {
+      Set<ObjectName> objectNames =
+          mBeanServer.queryNames(new ObjectName(DEFAULT_METRIC_DOMAIN + ":*"), null);
 
-    for (String appName : appNames) {
-      Assert.assertTrue(namespaces.contains(appName), String
-          .format("Application name: %s is not one of the namespaces: %s.", appName, namespaces));
-      namespaces.remove(appName);
-    }
+      Set<String> appNames = new HashSet<>();
+      for (ObjectName mBeanName : objectNames) {
+        appNames.add(mBeanName.getKeyProperty("type"));
+      }
+      return namespaces.equals(appNames);
+    }, TestHelper.WAIT_DURATION);
   }
 }