dmvk commented on a change in pull request #16654:
URL: https://github.com/apache/flink/pull/16654#discussion_r680872174
##########
File path:
flink-runtime/src/test/java/org/apache/flink/runtime/webmonitor/threadinfo/JobVertexThreadInfoTrackerTest.java
##########
@@ -169,20 +168,32 @@ public void testCachedStatsUpdatedAfterRefreshInterval()
throws Exception {
/** Tests that cached results are removed within the cleanup interval. */
@Test
public void testCachedStatsCleanedAfterCleanupInterval() throws Exception {
- final Duration cleanUpInterval2 = Duration.ofMillis(10);
+ final Duration cleanUpInterval2 = Duration.ofMillis(1);
final long waitingTime = cleanUpInterval2.toMillis() + 10;
+ // use cache recording stats so we can check later that it evicted the
entry
+ Cache<JobVertexThreadInfoTracker.Key, JobVertexThreadInfoStats>
vertexStatsCache =
+ CacheBuilder.newBuilder()
+ .concurrencyLevel(1)
+ .expireAfterAccess(cleanUpInterval2.toMillis(),
TimeUnit.MILLISECONDS)
+ .recordStats()
+ .build();
final JobVertexThreadInfoTracker<JobVertexThreadInfoStats> tracker =
createThreadInfoTracker(
- cleanUpInterval2, STATS_REFRESH_INTERVAL,
threadInfoStatsDefaultSample);
- doInitialRequestAndVerifyResult(tracker);
+ cleanUpInterval2,
+ STATS_REFRESH_INTERVAL,
+ vertexStatsCache,
+ threadInfoStatsDefaultSample);
- // wait until we are ready to cleanup
+ // no stats yet, but the request triggers async collection of stats
+ assertFalse(tracker.getVertexStats(JOB_ID,
EXECUTION_JOB_VERTEX).isPresent());
+ // wait until the result is available
+ tracker.getResultAvailableFuture().get();
+ // wait for the cleanup time plus a little buffer
Thread.sleep(waitingTime);
Review comment:
We should try not to rely on custom timeouts, these usually result in
flaky tests and make tests slower in general.
In this case, we can simply register a custom `removalListener` for guava
cache, and await on `CountDownLatch`
eg.
```java
private static class LatchRemovalListener<K, V> implements
RemovalListener<K, V> {
private final CountDownLatch latch;
private LatchRemovalListener(CountDownLatch latch) {
this.latch = latch;
}
@Override
public void onRemoval(RemovalNotification<K, V> removalNotification)
{
latch.countDown();
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]