Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove extra indent

Copy link
Copy Markdown
Member

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

"Queue thread should be waiting"
);

long timeBeforeWait = time.milliseconds();
long waitTime5Ms = 5;
time.sleep(waitTime5Ms);
Expand All @@ -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(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could we extract a helper method for this waiting?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, there were 2 occurances. Thanks. Updated.

() -> queueThread.getState() == Thread.State.WAITING,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chia7712 shall I remove the extra indents ? Or it's ok to leave it as is ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is ok to leave it as is :)

"Queue thread should be waiting"
);

long timeBeforeDeferred = time.milliseconds();
long waitTime2Ms = 2;
CompletableFuture<Void> deferredEvent2 = new CompletableFuture<>();
Expand Down
Loading