Skip to content

Commit d8281a1

Browse files
yaturnerclaude
andcommitted
ADFA-4484 Fix flawed KeyedDebouncingActionTest debounce window test
The previous test scheduled three different string keys ("first", "second", "third"), which created three independent channel entries rather than coalescing — causing all three actions to fire. Replace with a test that schedules the same key twice with a delay shorter than the debounce window, verifying the window resets and the action fires exactly once. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent bd9c5ed commit d8281a1

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

‎common/src/test/java/com/itsaky/androidide/utils/KeyedDebouncingActionTest.kt‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,20 @@ class KeyedDebouncingActionTest {
5454
}
5555

5656
@Test
57-
fun `last value wins when multiple sends arrive before debounce window`() = runBlocking {
58-
val received = CopyOnWriteArrayList<String>()
57+
fun `late reschedule of same key extends debounce window and fires exactly once`() = runBlocking {
58+
val count = AtomicInteger(0)
5959
val debouncer = KeyedDebouncingAction<String>(
6060
scope = makeScope(),
61-
debounceDuration = 100.milliseconds,
62-
action = { key, _ -> received.add(key) }
61+
debounceDuration = 150.milliseconds,
62+
action = { _, _ -> count.incrementAndGet() }
6363
)
6464

65-
debouncer.schedule("first")
66-
debouncer.schedule("second")
67-
debouncer.schedule("third")
68-
delay(400)
65+
debouncer.schedule("k")
66+
delay(80) // before debounce fires
67+
debouncer.schedule("k") // resets the debounce window
68+
delay(500)
6969

70-
// Since the channel is CONFLATED, only the most-recently sent value survives
71-
assertThat(received).hasSize(1)
70+
assertThat(count.get()).isEqualTo(1)
7271
debouncer.cancelAll()
7372
}
7473

0 commit comments

Comments
 (0)