Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ assertk = "com.willowtreeapps.assertk:assertk:0.28.1"
junit5-jupiter = "org.junit.jupiter:junit-jupiter:6.0.3"
junit-launcher = "org.junit.platform:junit-platform-launcher:6.0.3"
junit4 = "junit:junit:4.13.2"
kotlin-coroutines-test = "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.10.2"
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }

semver = "net.swiftzer.semver:semver:2.1.0"
Expand Down
1 change: 1 addition & 0 deletions tools/idea-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ dependencies {
testImplementation(testFixtures(projects.sdk.intellij.testFixtures))
testImplementation(libs.bundles.kmp.test)
testImplementation(libs.junit5.jupiter)
testImplementation(libs.kotlin.coroutines.test)
testRuntimeOnly(libs.junit.launcher)

intellijPlatform {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package io.github.composegears.valkyrie.ui.screen.webimport.svg.common.data
import assertk.assertFailure
import assertk.assertThat
import assertk.assertions.isEqualTo
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test

class SvgPreviewCacheTest {

@Test
fun `cache reuses loaded preview by key`() = runBlocking {
fun `cache reuses loaded preview by key`() = runTest {
val cache = SvgPreviewCache<String>()
var loadCount = 0

Expand All @@ -32,7 +33,7 @@ class SvgPreviewCacheTest {
}

@Test
fun `cache evicts least recently used preview when full`() = runBlocking {
fun `cache evicts least recently used preview when full`() = runTest {
val cache = SvgPreviewCache<String>(maxEntries = 2)

cache.getOrLoad("first") { "one" }
Expand All @@ -46,15 +47,15 @@ class SvgPreviewCacheTest {
}

@Test
fun `cache deduplicates concurrent loads for same key`() = runBlocking {
fun `cache deduplicates concurrent loads for same key`() = runTest {
val cache = SvgPreviewCache<String>()
var loadCount = 0

val previews = List(8) {
async(Dispatchers.Default) {
cache.getOrLoad("same") {
loadCount++
delay(10)
delay(10.milliseconds)
"preview"
}
}
Expand All @@ -65,7 +66,7 @@ class SvgPreviewCacheTest {
}

@Test
fun `cache removes key lock when loader fails`() = runBlocking {
fun `cache removes key lock when loader fails`() = runTest {
val cache = SvgPreviewCache<String>()
var loadCount = 0

Expand Down
Loading