|
20 | 20 |
|
21 | 21 | package land.oras.auth; |
22 | 22 |
|
| 23 | +import static org.awaitility.Awaitility.await; |
23 | 24 | import static org.junit.jupiter.api.Assertions.assertEquals; |
24 | | -import static org.junit.jupiter.api.Assertions.assertNull; |
25 | 25 | import static org.junit.jupiter.api.Assertions.assertTrue; |
26 | 26 |
|
27 | 27 | import io.micrometer.core.instrument.FunctionCounter; |
28 | 28 | import io.micrometer.core.instrument.MeterRegistry; |
29 | 29 | import io.micrometer.core.instrument.simple.SimpleMeterRegistry; |
| 30 | +import java.util.concurrent.TimeUnit; |
30 | 31 | import land.oras.ContainerRef; |
31 | 32 | import land.oras.TestUtils; |
32 | 33 | import org.junit.jupiter.api.BeforeAll; |
@@ -80,16 +81,13 @@ void shouldAddAndRetrieveTokenThenExpiredIt() throws InterruptedException { |
80 | 81 | Scopes scopes = Scopes.of(containerRef, Scope.PULL).withService("dockerhub"); // Pull only |
81 | 82 | TokenCache.put(scopes, tokenResponse); |
82 | 83 | assertEquals(tokenResponse, TokenCache.get(scopes), "Should retrieve the token before expiration"); |
83 | | - Thread.sleep(3000); // Wait for the token to expire |
84 | | - assertNull(TokenCache.get(scopes), "Should return null after token expiration"); |
| 84 | + await().atMost(10, TimeUnit.SECONDS) |
| 85 | + .until(() -> TokenCache.get(scopes) == null |
| 86 | + && meterRegistry.find("cache.evictions").functionCounters().stream() |
| 87 | + .mapToDouble(FunctionCounter::count) |
| 88 | + .sum() |
| 89 | + >= 1); |
85 | 90 | TestUtils.dumpMetrics(meterRegistry); |
86 | | - // At least one eviction |
87 | | - assertTrue( |
88 | | - meterRegistry.find("cache.evictions").functionCounters().stream() |
89 | | - .mapToDouble(FunctionCounter::count) |
90 | | - .sum() |
91 | | - >= 1, |
92 | | - "Should have at least one eviction"); |
93 | 91 | } |
94 | 92 |
|
95 | 93 | @Test |
|
0 commit comments