Skip to content

Commit

Permalink
#12268 do not rely on time
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
  • Loading branch information
lorban committed Sep 16, 2024
1 parent 2018c43 commit ceee65a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,14 @@ public void abort(Throwable 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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,17 @@ protected Action process()
{
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;
Expand All @@ -76,7 +84,7 @@ protected Action process()

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

Expand Down

0 comments on commit ceee65a

Please sign in to comment.