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 <[email protected]>
  • Loading branch information
lorban committed Sep 13, 2024
1 parent 5fb6ac6 commit c76b435
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 c76b435

Please sign in to comment.