touchlab / KaMPKit

KaMP Kit by Touchlab. A collection of code & tools designed to get your mobile team started quickly w/Kotlin Multiplatform
https://touchlab.co/
Apache License 2.0
2.2k stars 199 forks source link

Adds tests for BreedModel view update and error update callbacks #71

Closed ecgreb closed 4 years ago

ecgreb commented 4 years ago

Overview

Adds tests for BreedModel view update and error update callbacks.

Proposed Changes

ecgreb commented 4 years ago

I was hoping that using runBlockingTest() would force the DB flow to emit before finishing the test but it appears there is still a race condition between .collect { summary -> viewUpdate(summary) } in BreedModel and assertNotNull(itemDataSummary) in the test.

When I run locally sometimes it passes and sometimes the test fails.

Any ideas how to wait for the DB flow to emit before executing the assertion without resorting to sleep/delay statements? @russhwolf @kpgalligan

russhwolf commented 4 years ago

runBlockingTest() only exists for JVM anyway, so that isn't going to work. The iOS tests don't compile in this branch.

As to the particular test issues, I haven't looked super closely but one approach is to grab the Job from any internal launch calls and join() it, which will suspend until it completes. That should work fine inside runBlocking() (which we expose to common via runTest()) but any delay() calls would not get sped up.