#12268 do not rely on time
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
parent
2018c439b6
commit
ceee65a7e5
|
@ -545,6 +545,14 @@ public abstract class IteratingCallback implements Callback
|
||||||
onCompleteFailure(failure);
|
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
|
* @return whether this callback is idle, and {@link #iterate()} needs to be called
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -65,9 +65,17 @@ public class IteratingCallbackTest
|
||||||
{
|
{
|
||||||
iterate();
|
iterate();
|
||||||
if (succeededWinsRace)
|
if (succeededWinsRace)
|
||||||
|
{
|
||||||
succeeded();
|
succeeded();
|
||||||
|
}
|
||||||
else
|
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.SCHEDULED;
|
||||||
}
|
}
|
||||||
return Action.IDLE;
|
return Action.IDLE;
|
||||||
|
@ -76,7 +84,7 @@ public class IteratingCallbackTest
|
||||||
|
|
||||||
icb.iterate();
|
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);
|
assertEquals(2, icb.counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue