#12268 do not rely on time

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
Ludovic Orban 2024-09-13 10:31:22 +02:00
parent 2018c439b6
commit ceee65a7e5
2 changed files with 18 additions and 2 deletions

View File

@ -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
*/

View File

@ -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);
}