Skip to content

Commit eefedab

Browse files
egorikftpt-regbs
authored andcommitted
Use kotlin-coroutines-test for SvgPreviewCacheTest
1 parent b32cefd commit eefedab

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ assertk = "com.willowtreeapps.assertk:assertk:0.28.1"
4747
junit5-jupiter = "org.junit.jupiter:junit-jupiter:6.0.3"
4848
junit-launcher = "org.junit.platform:junit-platform-launcher:6.0.3"
4949
junit4 = "junit:junit:4.13.2"
50+
kotlin-coroutines-test = "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.10.2"
5051
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
5152

5253
semver = "net.swiftzer.semver:semver:2.1.0"

tools/idea-plugin/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ dependencies {
7474
testImplementation(testFixtures(projects.sdk.intellij.testFixtures))
7575
testImplementation(libs.bundles.kmp.test)
7676
testImplementation(libs.junit5.jupiter)
77+
testImplementation(libs.kotlin.coroutines.test)
7778
testRuntimeOnly(libs.junit.launcher)
7879

7980
intellijPlatform {

tools/idea-plugin/src/test/kotlin/io/github/composegears/valkyrie/ui/screen/webimport/svg/common/data/SvgPreviewCacheTest.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ package io.github.composegears.valkyrie.ui.screen.webimport.svg.common.data
33
import assertk.assertFailure
44
import assertk.assertThat
55
import assertk.assertions.isEqualTo
6+
import kotlin.time.Duration.Companion.milliseconds
67
import kotlinx.coroutines.Dispatchers
78
import kotlinx.coroutines.async
89
import kotlinx.coroutines.awaitAll
910
import kotlinx.coroutines.delay
10-
import kotlinx.coroutines.runBlocking
11+
import kotlinx.coroutines.test.runTest
1112
import org.junit.jupiter.api.Test
1213

1314
class 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

Comments
 (0)