Skip to content

Commit

Permalink
YARN-11390. TestResourceTrackerService.testNodeRemovalNormally: Shutd…
Browse files Browse the repository at this point in the history
…own nodes should be 0 now expected: <1> but was: <0>

- The hardcoded sleep what was used in the test was not the most stable solution
- It was replaced with a polling assert
  • Loading branch information
K0K0V0K committed Dec 7, 2022
1 parent 5fc63f9 commit 7b0d179
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import javax.xml.parsers.DocumentBuilderFactory;
Expand Down Expand Up @@ -2961,17 +2962,15 @@ protected ResourceTrackerService createResourceTrackerService() {
}

private void pollingAssert(Supplier<Boolean> supplier, String message)
throws InterruptedException {
pollingAssert(supplier, true, message);
throws InterruptedException, TimeoutException {
GenericTestUtils.waitFor(supplier,
100, 10_000, message);
}

private <T> void pollingAssert(Supplier<T> supplier, T expected, String message)
throws InterruptedException {
long timeOut = System.currentTimeMillis() + 10_000;
while (System.currentTimeMillis() < timeOut && !Objects.equals(expected, supplier.get())) {
Thread.sleep(100);
}
Assert.assertEquals(message, expected, supplier.get());
throws InterruptedException, TimeoutException {
GenericTestUtils.waitFor(() -> Objects.equals(supplier.get(), expected),
100, 10_000, message);
}

/**
Expand Down

0 comments on commit 7b0d179

Please sign in to comment.