jeffkbkim commented on code in PR #17221: URL: https://github.com/apache/kafka/pull/17221#discussion_r1772911560
########## coordinator-common/src/test/java/org/apache/kafka/coordinator/common/runtime/HdrHistogramTest.java: ########## @@ -172,4 +177,39 @@ public void testHistogramDataReset() { assertEquals(numEventsInFirstCycle, hdrHistogram.count(now + maxSnapshotAgeMs)); assertEquals(numEventsInSecondCycle, hdrHistogram.count(now + 1 + maxSnapshotAgeMs)); } + + @Test + public void testLatestHistogramRace() throws InterruptedException, ExecutionException { + long maxSnapshotAgeMs = 10L; + long now = System.currentTimeMillis(); + HdrHistogram hdrHistogram = new HdrHistogram(maxSnapshotAgeMs, MAX_VALUE, 1); + ExecutorService countExecutor = Executors.newFixedThreadPool(2); + for (int i = 1; i < 10000; i++) { + int numEvents = 2; + for (int j = 0; j < numEvents; j++) { + hdrHistogram.record(i); + } + final long moreThanMaxAge = now + maxSnapshotAgeMs + 1; + now = moreThanMaxAge; + CountDownLatch latch = new CountDownLatch(1); + Callable<Long> countTask = () -> { + try { + assertTrue(latch.await(500, TimeUnit.MILLISECONDS)); Review Comment: my understanding is that the main thread may count down the latch before the threads reach latch.await() which then loses its purpose. this could happen right? regardless, i think your explanation makes sense. thanks! -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org