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

cnauroth pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new eb85f8cc6a4 YARN-11934. Fix testComponentHealthThresholdMonitor race 
condition.
eb85f8cc6a4 is described below

commit eb85f8cc6a452275fb35d4b28d4e3c637f3d9521
Author: slfan1989 <[email protected]>
AuthorDate: Mon Feb 23 17:19:24 2026 +0000

    YARN-11934. Fix testComponentHealthThresholdMonitor race condition.
    
    Closes #8266
    
    Signed-off-by: Chris Nauroth <[email protected]>
---
 .../yarn/service/TestYarnNativeServices.java       | 42 ++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestYarnNativeServices.java
 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestYarnNativeServices.java
index 75985f5c844..0c74cd2cb98 100644
--- 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestYarnNativeServices.java
+++ 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestYarnNativeServices.java
@@ -789,6 +789,7 @@ public void testComponentHealthThresholdMonitor() throws 
Exception {
     compCounts.put("compa", 4L);
     exampleApp.getComponent("compa").setNumberOfContainers(4L);
     client.flexByRestService(exampleApp.getName(), compCounts);
+    waitForServiceToLeaveStable(client, exampleApp, 10_000, "compa");
     try {
       // Wait for 6 secs (window 3 secs + 1 for next poll + 2 for buffer). 
Since
       // the service will never go to stable state (because of anti-affinity 
the
@@ -815,6 +816,7 @@ public void testComponentHealthThresholdMonitor() throws 
Exception {
     compCounts.put("compa", 5L);
     exampleApp.getComponent("compa").setNumberOfContainers(5L);
     client.flexByRestService(exampleApp.getName(), compCounts);
+    waitForServiceToLeaveStable(client, exampleApp, 10_000, "compa");
     try {
       // Wait for 14 secs (window 3 secs + 1 for next poll + 2 for buffer + 5
       // secs of service wait before shutting down + 3 secs app cleanup so that
@@ -860,6 +862,46 @@ private void 
checkContainerLaunchDependencies(ServiceClient client,
     }
   }
 
+  /**
+   * Wait for the service to leave STABLE state after a flex operation.
+   * This ensures the flex has taken effect before proceeding.
+   *
+   * @param client the service client
+   * @param service the service being flexed
+   * @param waitForMillis maximum wait time in milliseconds
+   * @param componentNames the component names to check for non-stable state
+   * @throws TimeoutException if service doesn't leave stable within timeout
+   * @throws InterruptedException if wait is interrupted
+   */
+  private void waitForServiceToLeaveStable(ServiceClient client, Service 
service,
+      int waitForMillis, String... componentNames)
+      throws TimeoutException, InterruptedException {
+    GenericTestUtils.waitFor(() -> {
+      try {
+        Service status = client.getStatus(service.getName());
+        if (status.getState() != ServiceState.STABLE) {
+          return true;
+        }
+        if (componentNames == null || componentNames.length == 0) {
+          return false;
+        }
+        for (String componentName : componentNames) {
+          Component component = status.getComponent(componentName);
+          if (component == null) {
+            return false;
+          }
+          if (component.getState() != ComponentState.STABLE) {
+            return true;
+          }
+        }
+        return false;
+      } catch (Exception e) {
+        LOG.debug("Waiting for service to leave STABLE failed to fetch 
status", e);
+        return false;
+      }
+    }, 500, waitForMillis);
+  }
+
 
   private Map<String, Long> flexComponents(ServiceClient client,
       Service exampleApp, long count) throws YarnException, IOException {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to