From ceee65a7e509a767c0127b4d5f2111fb79803d8c Mon Sep 17 00:00:00 2001 From: Ludovic Orban Date: Fri, 13 Sep 2024 10:31:22 +0200 Subject: [PATCH] #12268 do not rely on time Signed-off-by: Ludovic Orban --- .../org/eclipse/jetty/util/IteratingCallback.java | 8 ++++++++ .../eclipse/jetty/util/IteratingCallbackTest.java | 12 ++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/IteratingCallback.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/IteratingCallback.java index 9cd22280508..0d71ce2f73f 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/IteratingCallback.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/IteratingCallback.java @@ -545,6 +545,14 @@ public abstract class IteratingCallback implements Callback onCompleteFailure(failure); } + boolean isPending() + { + try (AutoLock ignored = _lock.lock()) + { + return _state == State.PENDING; + } + } + /** * @return whether this callback is idle, and {@link #iterate()} needs to be called */ diff --git a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/IteratingCallbackTest.java b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/IteratingCallbackTest.java index bba07604ddd..edc02749b95 100644 --- a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/IteratingCallbackTest.java +++ b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/IteratingCallbackTest.java @@ -65,9 +65,17 @@ public class IteratingCallbackTest { iterate(); if (succeededWinsRace) + { succeeded(); + } else - scheduler.schedule(this::succeeded, 100, TimeUnit.MILLISECONDS); + { + new Thread(() -> + { + await().atMost(5, TimeUnit.SECONDS).until(this::isPending, is(true)); + succeeded(); + }).start(); + } return Action.SCHEDULED; } return Action.IDLE; @@ -76,7 +84,7 @@ public class IteratingCallbackTest icb.iterate(); - await().atMost(5, TimeUnit.SECONDS).until(icb::isIdle, is(true)); + await().atMost(10, TimeUnit.SECONDS).until(icb::isIdle, is(true)); assertEquals(2, icb.counter); }