Skip to content

YARN-11816. Fix flaky test: TestCapacitySchedulerMultiNodes#testCheckRequestOnceForUnsatisfiedRequest #7659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.when;

Expand All @@ -35,8 +34,10 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.thirdparty.com.google.common.collect.Iterators;

import org.apache.hadoop.yarn.server.resourcemanager.RMContext;
Expand Down Expand Up @@ -625,7 +626,6 @@ public void testCheckRequestOnceForUnsatisfiedRequest() throws Exception {
// mock node tracker with 2000 nodes
// to simulate the scenario where there are many nodes in the cluster
List<FiCaSchedulerNode> mockNodes = new ArrayList<>();
long ss = System.currentTimeMillis();
for (int i = 0; i < 2000; i++) {
FiCaSchedulerNode node =
TestUtils.getMockNode("host" + i + ":1234", "", 0, 10 * GB, 10);
Expand Down Expand Up @@ -660,26 +660,34 @@ public List<FiCaSchedulerNode> getNodesPerPartition(String partition) {
// create an unsatisfied request which will reach the headroom
am1.allocate("*", 2 * GB, 10, new ArrayList<>());

// verify that when headroom is reached for an unsatisfied request,
// scheduler should only check the request once before checking all nodes.
CandidateNodeSet<FiCaSchedulerNode> candidates =
new SimpleCandidateNodeSet<>(Collections.emptyMap(), "");
int numSchedulingCycles = 10;
long startTime = System.currentTimeMillis();
for (int i = 0; i < numSchedulingCycles; i++) {
spyCs.allocateContainersToNode(candidates, false);
List<Long> elapsedMsLst = new ArrayList<>();
try {
GenericTestUtils.waitFor(() -> {
// verify that when headroom is reached for an unsatisfied request,
// scheduler should only check the request once before checking all nodes.
CandidateNodeSet<FiCaSchedulerNode> candidates =
new SimpleCandidateNodeSet<>(Collections.emptyMap(), "");
int numSchedulingCycles = 10;
long startTime = System.currentTimeMillis();
for (int i = 0; i < numSchedulingCycles; i++) {
spyCs.allocateContainersToNode(candidates, false);
}
long avgElapsedMs =
(System.currentTimeMillis() - startTime) / numSchedulingCycles;
LOG.info("Average elapsed time for a scheduling cycle: {} ms",
avgElapsedMs);

elapsedMsLst.add(avgElapsedMs);
// verify that the scheduling cycle is less than 10ms,
// ideally the latency should be less than 2ms.
return avgElapsedMs < 10;
}, 500, 3000);
} catch (TimeoutException e) {
fail("Scheduling cycle expected to be less than 10ms, " +
"but took too long, elapsedMs:" + elapsedMsLst);
} finally {
rm.stop();
}
long avgElapsedMs =
(System.currentTimeMillis() - startTime) / numSchedulingCycles;
LOG.info("Average elapsed time for a scheduling cycle: {} ms",
avgElapsedMs);
// verify that the scheduling cycle is less than 5ms,
// ideally the latency should be less than 2ms.
assertTrue(avgElapsedMs < 5,
String.format("%d ms elapsed in average for a scheduling cycle, " +
"expected to be less than 5ms.", avgElapsedMs));

rm.stop();
}

private static void moveReservation(CapacityScheduler cs,
Expand Down