如何使用 Awaitility 至少等待指定的时间?

How can I await at least specified amount of time with Awaitility?

我在考试class我真的需要睡一段时间。这是一个涉及定期远程调用的集成测试。

for (int i = 0; i < 16; i++) {
    // sleep some... should sleep some...
    Thread.sleep((int) TimeUnit.MINUTES.toMillis(4L)); // means as it means.
    // call remote api and check the response.
}

使用 Awaitility 的等效表达式是什么?

我试过了...

// Let's sleep for 4 minutes, no matter what happen!
Awaitility.await()
        .atLeast(Duration.ofMinutes(4L)) // what the hell does this mean, anyway?
        .untilTrue(new AtomicBoolean(false));

似乎在默认轮询间隔之后触发了超时。

这种情况第一次使用Awaitillity不行吗?

答案可能为时已晚,但有几种方法可以做到。

这告诉 awaitility 有 4 分钟的轮询延迟。因此,请等待 4 分钟后再进行断言。

Awaitility.await().pollDelay(4, TimeUnit.MINUTES).untilAsserted(() -> Assert.assertTrue(true));