mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-08 09:47:09 +00:00
add one more test for SmartKeyRWLocker
This commit is contained in:
@@ -14,7 +14,7 @@ import kotlin.time.Duration.Companion.seconds
|
|||||||
|
|
||||||
class SmartKeyRWLockerTests {
|
class SmartKeyRWLockerTests {
|
||||||
@Test
|
@Test
|
||||||
fun lockKeyFailedOnGlobalLockTest() = runTest {
|
fun writeLockKeyFailedOnGlobalWriteLockTest() = runTest {
|
||||||
val locker = SmartKeyRWLocker<String>()
|
val locker = SmartKeyRWLocker<String>()
|
||||||
val testKey = "test"
|
val testKey = "test"
|
||||||
locker.lockWrite()
|
locker.lockWrite()
|
||||||
@@ -39,6 +39,31 @@ class SmartKeyRWLockerTests {
|
|||||||
assertFalse { locker.isWriteLocked(testKey) }
|
assertFalse { locker.isWriteLocked(testKey) }
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
|
fun writeLockKeyFailedOnGlobalReadLockTest() = runTest {
|
||||||
|
val locker = SmartKeyRWLocker<String>()
|
||||||
|
val testKey = "test"
|
||||||
|
locker.acquireRead()
|
||||||
|
|
||||||
|
assertEquals(Int.MAX_VALUE - 1, locker.readSemaphore().freePermits)
|
||||||
|
|
||||||
|
assertFails {
|
||||||
|
realWithTimeout(1.seconds) {
|
||||||
|
locker.lockWrite(testKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertFalse { locker.isWriteLocked(testKey) }
|
||||||
|
|
||||||
|
locker.releaseRead()
|
||||||
|
assertEquals(Int.MAX_VALUE, locker.readSemaphore().freePermits)
|
||||||
|
|
||||||
|
realWithTimeout(1.seconds) {
|
||||||
|
locker.lockWrite(testKey)
|
||||||
|
}
|
||||||
|
assertTrue { locker.isWriteLocked(testKey) }
|
||||||
|
assertTrue { locker.unlockWrite(testKey) }
|
||||||
|
assertFalse { locker.isWriteLocked(testKey) }
|
||||||
|
}
|
||||||
|
@Test
|
||||||
fun readsBlockingGlobalWrite() = runTest {
|
fun readsBlockingGlobalWrite() = runTest {
|
||||||
val locker = SmartKeyRWLocker<String>()
|
val locker = SmartKeyRWLocker<String>()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user