Compare commits

...

3 Commits

Author SHA1 Message Date
d46cc3b09c remove redundant commentaries 2025-03-25 17:45:53 +06:00
dfd23f8d60 update kotlin 2025-03-25 17:42:32 +06:00
28eb1a11e6 add more tests for smart key rw locker tests 2025-03-25 17:27:34 +06:00
3 changed files with 59 additions and 7 deletions

View File

@@ -64,6 +64,56 @@ class SmartKeyRWLockerTests {
assertFalse { locker.isWriteLocked(testKey) }
}
@Test
fun readLockFailedOnWriteLockKeyTest() = runTest {
val locker = SmartKeyRWLocker<String>()
val testKey = "test"
locker.lockWrite(testKey)
assertTrue { locker.isWriteLocked(testKey) }
assertFails {
realWithTimeout(1.seconds) {
locker.acquireRead()
}
}
assertEquals(locker.readSemaphore().maxPermits - 1, locker.readSemaphore().freePermits)
locker.unlockWrite(testKey)
assertFalse { locker.isWriteLocked(testKey) }
realWithTimeout(1.seconds) {
locker.acquireRead()
}
assertEquals(locker.readSemaphore().maxPermits - 1, locker.readSemaphore().freePermits)
assertTrue { locker.releaseRead() }
assertEquals(locker.readSemaphore().maxPermits, locker.readSemaphore().freePermits)
}
@Test
fun writeLockFailedOnWriteLockKeyTest() = runTest {
val locker = SmartKeyRWLocker<String>()
val testKey = "test"
locker.lockWrite(testKey)
assertTrue { locker.isWriteLocked(testKey) }
assertFails {
realWithTimeout(1.seconds) {
locker.lockWrite()
}
}
assertFalse(locker.isWriteLocked())
locker.unlockWrite(testKey)
assertFalse { locker.isWriteLocked(testKey) }
realWithTimeout(1.seconds) {
locker.lockWrite()
}
assertTrue(locker.isWriteLocked())
assertTrue { locker.unlockWrite() }
assertFalse(locker.isWriteLocked())
}
@Test
fun readsBlockingGlobalWrite() = runTest {
val locker = SmartKeyRWLocker<String>()

View File

@@ -1,6 +1,6 @@
[versions]
kt = "2.1.10"
kt = "2.1.20"
kt-serialization = "1.8.0"
kt-coroutines = "1.10.1"
@@ -23,7 +23,7 @@ koin = "4.0.2"
okio = "3.10.2"
ksp = "2.1.10-1.0.31"
ksp = "2.1.20-1.0.31"
kotlin-poet = "1.18.1"
versions = "0.51.0"

View File

@@ -1,13 +1,19 @@
plugins {
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization"
id "application"
id "com.google.devtools.ksp"
}
apply from: "$mppJvmJsLinuxMingwProject"
kotlin {
jvm {
binaries {
executable {
mainClass.set("dev.inmo.micro_utils.startup.launcher.MainKt")
}
}
}
sourceSets {
commonMain {
dependencies {
@@ -23,10 +29,6 @@ kotlin {
}
}
application {
mainClassName = "dev.inmo.micro_utils.startup.launcher.MainKt"
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17