Oleksii Malovanyi
09/17/2021, 2:29 PMrunOnCreate
function so one could subscribe to container from it -> currently it’s impossible due to compilation restrictions, so in case of ViewModel we have to subscribe from the `init{}`which then could affect tests which don’t wanna run runOnCreate
on TestContainerOleksii Malovanyi
09/17/2021, 2:30 PMonCreate: Container<STATE, SIDE_EFFECT>.(state: STATE) -> Unit
Oleksii Malovanyi
09/17/2021, 5:00 PMOleksii Malovanyi
09/17/2021, 5:52 PMonCreate
then runOnCreate
test would never finish (obviously). Maybe, we could add a param to runOnCreate
to indicate it should terminate with timeout silently. e.g.
runOnCreate(withTimeout:Long = 0L)
and if withTimeout
> 0 wrap the call with withTimeoutOrNull
.appmattus
09/21/2021, 1:22 PMMikolaj Leszczynski
09/22/2021, 8:31 AMContainerHost
function invoking intent
where you can subscribe to the container?Mikolaj Leszczynski
09/22/2021, 8:43 AMprivate inner class SomeMiddleware : ContainerHost<TestState, String> {
override val container = scope.container<TestState, String>(TestState(42)) {
test()
}
private fun test(): Unit = intent {
coroutineScope {
container.stateFlow.collect {
println("TEST LOL $it")
}
}
}
}
Mikolaj Leszczynski
09/22/2021, 8:43 AMMikolaj Leszczynski
09/22/2021, 8:47 AMfun test
you’re goldenMikolaj Leszczynski
09/22/2021, 12:22 PMonCreate
Oleksii Malovanyi
09/22/2021, 2:18 PMOleksii Malovanyi
09/22/2021, 2:20 PMOleksii Malovanyi
09/22/2021, 2:21 PMOleksii Malovanyi
09/22/2021, 2:24 PMrunOnCreate
with infinite collection of the state runBlockingTest
will punch you for that (obviously indefinite collection is not allowed in tests), as it blocks. The solution is to create a coroutine or something similar for the collection – withTimeoutOrNull
works then, but looks kinda ugly 🤔Oleksii Malovanyi
09/22/2021, 2:25 PMMikolaj Leszczynski
09/22/2021, 2:45 PMrunOnCreate
set to off. Am I missing something?Oleksii Malovanyi
09/22/2021, 2:47 PMrunBlockingTest
, but! There is a case when you have to start runOnCreate
going (for the collection) and still do testIntent
for the rollback-state on smth bad happens scenarioMikolaj Leszczynski
09/22/2021, 2:55 PMOleksii Malovanyi
09/22/2021, 2:56 PMMikolaj Leszczynski
09/22/2021, 3:00 PMOleksii Malovanyi
09/22/2021, 3:00 PMMikolaj Leszczynski
09/22/2021, 3:01 PMMikolaj Leszczynski
09/22/2021, 3:01 PMMikolaj Leszczynski
09/22/2021, 3:01 PMMikolaj Leszczynski
09/22/2021, 3:01 PMMikolaj Leszczynski
09/22/2021, 5:11 PMMikolaj Leszczynski
09/24/2021, 7:37 AMOleksii Malovanyi
09/24/2021, 7:38 AMMikolaj Leszczynski
09/24/2021, 7:38 AM