diff --git a/bifromq-retain/bifromq-retain-store/src/test/java/com/baidu/bifromq/retain/store/LoadMetadataTest.java b/bifromq-retain/bifromq-retain-store/src/test/java/com/baidu/bifromq/retain/store/LoadMetadataTest.java index c59f6e023..deba912d6 100644 --- a/bifromq-retain/bifromq-retain-store/src/test/java/com/baidu/bifromq/retain/store/LoadMetadataTest.java +++ b/bifromq-retain/bifromq-retain-store/src/test/java/com/baidu/bifromq/retain/store/LoadMetadataTest.java @@ -17,6 +17,7 @@ import static org.testng.Assert.assertNotSame; import io.micrometer.core.instrument.Gauge; +import java.time.Duration; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -34,8 +35,8 @@ public void testLoadMetadata() { requestRetain(tenantId, message("/b", "hello")); Gauge spaceUsageGauge = getSpaceUsageGauge(tenantId); Gauge retainCountGauge = getRetainCountGauge(tenantId); - await().until(() -> spaceUsageGauge.value() > 0); - await().until(() -> retainCountGauge.value() == 2); + await().atMost(Duration.ofSeconds(20)).until(() -> spaceUsageGauge.value() > 0); + await().atMost(Duration.ofSeconds(20)).until(() -> retainCountGauge.value() == 2); restartStoreServer(); storeClient.join(); @@ -44,7 +45,7 @@ public void testLoadMetadata() { Gauge newRetainCountGauge = getRetainCountGauge(tenantId); assertNotSame(spaceUsageGauge, newSpaceUsageGauge); assertNotSame(retainCountGauge, newRetainCountGauge); - await().until(() -> newSpaceUsageGauge.value() > 0); - await().until(() -> newRetainCountGauge.value() == 2); + await().atMost(Duration.ofSeconds(20)).until(() -> newSpaceUsageGauge.value() > 0); + await().atMost(Duration.ofSeconds(20)).until(() -> newRetainCountGauge.value() == 2); } } diff --git a/bifromq-retain/bifromq-retain-store/src/test/java/com/baidu/bifromq/retain/store/RetainStoreTest.java b/bifromq-retain/bifromq-retain-store/src/test/java/com/baidu/bifromq/retain/store/RetainStoreTest.java index 052b2a26f..2cf94d173 100644 --- a/bifromq-retain/bifromq-retain-store/src/test/java/com/baidu/bifromq/retain/store/RetainStoreTest.java +++ b/bifromq-retain/bifromq-retain-store/src/test/java/com/baidu/bifromq/retain/store/RetainStoreTest.java @@ -181,7 +181,6 @@ public void tearDown() throws Exception { closeable.close(); } - protected RetainResult.Code requestRetain(String tenantId, TopicMessage topicMsg) { long reqId = ThreadLocalRandom.current().nextInt(); ByteString tenantNS = KVSchemaUtil.tenantBeginKey(tenantId); @@ -266,7 +265,7 @@ protected void assertNoGauge(String tenantId, TenantMetric gaugeMetric) { protected Gauge getGauge(String tenantId, TenantMetric gaugeMetric) { AtomicReference holder = new AtomicReference<>(); - await().until(() -> { + await().atMost(Duration.ofSeconds(20)).until(() -> { for (Meter meter : meterRegistry.getMeters()) { if (meter.getId().getType() == Meter.Type.GAUGE && meter.getId().getName().equals(gaugeMetric.metricName) &&