Hey guys, me again ¯\_(ツ)_/¯ I’ve been adopting n...
# orbit-mvi
o
Hey guys, me again ¯\_(ツ)_/¯ I’ve been adopting new 4.0.0 test model and found an issue: the
exceptionHandler
is never used so any exception would go to the
TestCoroutineExceptionHandler
which would fail the test afterwards (runBlockingTest is used)
I’ve made an investigation and I think it happens because of the
InterceptingContainerDecorator
and
SuspendingTestContainerHost#suspendingIntent
-> the latest receives the intent in the context of the test which, of course, ignores the Settings’s
exceptionHandler
as a solution, what do you think about adding the
withContext
wrap in case there is
settings.exceptionHandler
exists – smth similar to the what RealContainer does
I mean this function
Copy code
@Suppress("EXPERIMENTAL_API_USAGE")
    private suspend fun <STATE : Any, SIDE_EFFECT : Any, T : ContainerHost<STATE, SIDE_EFFECT>> T.suspendingIntent(
        shouldIsolateFlow: Boolean,
        block: T.() -> Unit
    ) {
        val testContainer = container.findTestContainer()

        this.block() // Invoke the Intent

        if (testContainer.savedIntents.isEmpty) {
            throw IllegalArgumentException("testIntent block must invoke an orbit intent!")
        }

        var firstIntentExecuted = false
        while (!testContainer.savedIntents.isEmpty) {
            val intent = testContainer.savedIntents.receive()
            if (!shouldIsolateFlow || !firstIntentExecuted) {
                firstIntentExecuted = true

// WRAP withContext() here
                intent()
            }
        }
    }
I’ve created a PR to demonstrate the problem and the possible fix: https://github.com/orbit-mvi/orbit-mvi/pull/50 Please note, this is a draft and not a final solution, despite it works (at least with the ExceptionHandler tests)
m
yep that sounds about right, sorry about breaking this!
@Oleksii Malovanyi remind me why we installed the excpetion handler at the
orbit
function level, and not the container scope level?
is it because otherwise the orbit loop breaks after getting an exception?
yeah, I just answered my own question…
o
yeap, yeap, yeap 😅
m
I’ve commented on your PR
and sorry - I used Github’s new batch suggestion feature and didn’t realise it would actually commit those suggestions!
o
thanks I guess, why now? 🙂
m
at least now the tests are green 😛
so I guess my suggestion worked
o
@Mikolaj Leszczynski I’ve added small explanation to the tests why scope would be active, and that’s it from my side, all checks are green. Do you think this PR is ready for a review?
m
ready for merge even
😲 1
Thanks @Oleksii Malovanyi !
started the release process
o
metal metal metal
m
I think our treatment of scopes etc. could use an improvement though
one step at a time I guess 🙂
o
that’s tricky… I feel like I need to get back to documentation about the scopes to keep track on how do they work together
m
yes, it’s not an easy thing
I don’t have a clear idea of how to simplify and improve what we have
thanks a lot for your recent contributions, you’re pushing us to improve the library 🙂
o
thank you guys for a blazing fast response – that’s really valuable
m
❤️