-
Notifications
You must be signed in to change notification settings - Fork 15.1k
KAFKA-20363 : server-common - Fix flaky testIdleTimeCallback in KafkaEventQueueTest #21920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -440,6 +440,11 @@ public void testIdleTimeCallback() throws Exception { | |
| lastIdleTimeMs.set(idleDuration); | ||
| lastCurrentTimeMs.set(currentTime); | ||
| })) { | ||
| // Capture the queue's event handler thread so we can wait for it to be idle. | ||
| CompletableFuture<Thread> queueThreadFuture = new CompletableFuture<>(); | ||
| queue.append(() -> queueThreadFuture.complete(Thread.currentThread())); | ||
| Thread queueThread = queueThreadFuture.get(); | ||
|
|
||
| time.sleep(2); | ||
| assertEquals(0, lastIdleTimeMs.get(), "Last idle time should be 0ms"); | ||
|
|
||
|
|
@@ -451,6 +456,13 @@ public void testIdleTimeCallback() throws Exception { | |
| })); | ||
| assertEquals("event1-processed", event1.get()); | ||
|
|
||
| // Wait for the queue thread to enter cond.await() before advancing MockTime. | ||
| // This ensures startIdleMs is captured before the time advancement. | ||
| TestUtils.waitForCondition( | ||
| () -> queueThread.getState() == Thread.State.WAITING, | ||
| "Queue thread should be waiting" | ||
| ); | ||
|
|
||
| long timeBeforeWait = time.milliseconds(); | ||
| long waitTime5Ms = 5; | ||
| time.sleep(waitTime5Ms); | ||
|
|
@@ -464,6 +476,12 @@ public void testIdleTimeCallback() throws Exception { | |
| assertEquals(timeBeforeWait + waitTime5Ms, lastCurrentTimeMs.get(), "Current time should be " + (timeBeforeWait + waitTime5Ms) + "ms, was: " + lastCurrentTimeMs.get()); | ||
|
|
||
| // Test 2: Deferred event | ||
| // Wait for the queue thread to enter cond.await() before advancing MockTime. | ||
| TestUtils.waitForCondition( | ||
|
||
| () -> queueThread.getState() == Thread.State.WAITING, | ||
|
||
| "Queue thread should be waiting" | ||
| ); | ||
|
|
||
| long timeBeforeDeferred = time.milliseconds(); | ||
| long waitTime2Ms = 2; | ||
| CompletableFuture<Void> deferredEvent2 = new CompletableFuture<>(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove extra indent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see the 'extra' indent is the existing convention in this file. I'll withdraw my comment