mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-06 04:14:34 -05:00
* Add a test for `subscribeTo` * subscribeTo: Fix initial flow value sometimes not propagated Co-authored-by: schroda <50052685+schroda@users.noreply.github.com> Co-authored-by: Syer10 <mitchellptbo@gmail.com> * lint --------- Co-authored-by: schroda <50052685+schroda@users.noreply.github.com> Co-authored-by: Syer10 <mitchellptbo@gmail.com>
27 lines
793 B
Kotlin
27 lines
793 B
Kotlin
package suwayomi.tachidesk
|
|
|
|
import graphql.Assert.assertTrue
|
|
import kotlinx.coroutines.flow.MutableStateFlow
|
|
import kotlinx.coroutines.flow.first
|
|
import kotlinx.coroutines.test.runTest
|
|
import suwayomi.tachidesk.server.subscribeTo
|
|
import java.util.concurrent.CountDownLatch
|
|
import java.util.concurrent.TimeUnit
|
|
import kotlin.test.Test
|
|
|
|
class FlowTest {
|
|
@Test
|
|
fun subscribe() =
|
|
runTest {
|
|
(1..1000).forEach { _ ->
|
|
val testFlow = MutableStateFlow(value = 3)
|
|
testFlow.first()
|
|
val latch = CountDownLatch(1)
|
|
subscribeTo(testFlow, ignoreInitialValue = false) { _ ->
|
|
latch.countDown()
|
|
}
|
|
assertTrue(latch.await(5, TimeUnit.SECONDS))
|
|
}
|
|
}
|
|
}
|