mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-12-23 14:45:48 +00:00
add more tests for smart key rw locker tests
This commit is contained in:
@@ -64,6 +64,56 @@ class SmartKeyRWLockerTests {
|
|||||||
assertFalse { locker.isWriteLocked(testKey) }
|
assertFalse { locker.isWriteLocked(testKey) }
|
||||||
}
|
}
|
||||||
@Test
|
@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 {
|
fun readsBlockingGlobalWrite() = runTest {
|
||||||
val locker = SmartKeyRWLocker<String>()
|
val locker = SmartKeyRWLocker<String>()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user