Skip to content

Commit 062758d

Browse files
yinnhoclaude
andauthored
Fix racy cache-hit assertions in CacheManagerTest (#11)
The cache-hit path deliberately fires a deduped background refresh, so an assertion that the request count stays identical races the async job and loses on slow CI machines. Assert the cached value and allow at most one extra request instead. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent fc198e7 commit 062758d

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

app/src/test/java/com/yinnho/upnpcast/internal/core/CacheManagerTest.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,16 @@ class CacheManagerTest {
6262
val first = cacheManager.getProgress(controller)
6363
assertEquals(Pair(10000L, 600000L), first)
6464

65+
// A cache hit answers synchronously; the by-design background
66+
// refresh may fire at most one extra GetPositionInfo (deduped
67+
// while a job is active), racing with this assertion on slow
68+
// machines — accept either outcome
6569
val positionCallsAfterFirst = renderer.callsFor("GetPositionInfo").size
6670
val second = cacheManager.getProgress(controller)
6771
assertNotNull(second)
68-
assertEquals(positionCallsAfterFirst, renderer.callsFor("GetPositionInfo").size)
72+
assertEquals(600000L, second!!.second)
73+
val positionCallsAfterSecond = renderer.callsFor("GetPositionInfo").size
74+
assertTrue(positionCallsAfterSecond - positionCallsAfterFirst <= 1)
6975
}
7076

7177
@Test
@@ -89,9 +95,11 @@ class CacheManagerTest {
8995
fun volumeIsCachedWithMuteState() = runBlocking {
9096
assertEquals(Pair(30, false), cacheManager.getVolume(controller))
9197

98+
// Cache hit returns the cached pair; the background refresh may
99+
// add at most one GetVolume call racing this assertion
92100
val volumeCallsAfterFirst = renderer.callsFor("GetVolume").size
93101
assertEquals(Pair(30, false), cacheManager.getVolume(controller))
94-
assertEquals(volumeCallsAfterFirst, renderer.callsFor("GetVolume").size)
102+
assertTrue(renderer.callsFor("GetVolume").size - volumeCallsAfterFirst <= 1)
95103
}
96104

97105
@Test

0 commit comments

Comments
 (0)