@@ -3,17 +3,18 @@ package io.github.composegears.valkyrie.ui.screen.webimport.svg.common.data
33import assertk.assertFailure
44import assertk.assertThat
55import assertk.assertions.isEqualTo
6+ import kotlin.time.Duration.Companion.milliseconds
67import kotlinx.coroutines.Dispatchers
78import kotlinx.coroutines.async
89import kotlinx.coroutines.awaitAll
910import kotlinx.coroutines.delay
10- import kotlinx.coroutines.runBlocking
11+ import kotlinx.coroutines.test.runTest
1112import org.junit.jupiter.api.Test
1213
1314class SvgPreviewCacheTest {
1415
1516 @Test
16- fun `cache reuses loaded preview by key` () = runBlocking {
17+ fun `cache reuses loaded preview by key` () = runTest {
1718 val cache = SvgPreviewCache <String >()
1819 var loadCount = 0
1920
@@ -32,7 +33,7 @@ class SvgPreviewCacheTest {
3233 }
3334
3435 @Test
35- fun `cache evicts least recently used preview when full` () = runBlocking {
36+ fun `cache evicts least recently used preview when full` () = runTest {
3637 val cache = SvgPreviewCache <String >(maxEntries = 2 )
3738
3839 cache.getOrLoad(" first" ) { " one" }
@@ -46,15 +47,15 @@ class SvgPreviewCacheTest {
4647 }
4748
4849 @Test
49- fun `cache deduplicates concurrent loads for same key` () = runBlocking {
50+ fun `cache deduplicates concurrent loads for same key` () = runTest {
5051 val cache = SvgPreviewCache <String >()
5152 var loadCount = 0
5253
5354 val previews = List (8 ) {
5455 async(Dispatchers .Default ) {
5556 cache.getOrLoad(" same" ) {
5657 loadCount++
57- delay(10 )
58+ delay(10 .milliseconds )
5859 " preview"
5960 }
6061 }
@@ -65,7 +66,7 @@ class SvgPreviewCacheTest {
6566 }
6667
6768 @Test
68- fun `cache removes key lock when loader fails` () = runBlocking {
69+ fun `cache removes key lock when loader fails` () = runTest {
6970 val cache = SvgPreviewCache <String >()
7071 var loadCount = 0
7172
0 commit comments