Kris Wong
02/05/2021, 4:37 PMsuspend
function within runBlocking
, the following code should not be executed until the function completes, correct? I am seeing some flakiness in a test that doesn't make sense to me.wasyl
02/05/2021, 4:38 PMrunBlocking
doesn’t change all suspend functions into blocking onesKris Wong
02/05/2021, 4:39 PMwasyl
02/05/2021, 4:39 PMthe test function or the suspending function?The test function
Kris Wong
02/05/2021, 4:40 PM@Test fun someTest() = runBlocking {
someSuspendingFunction()
assertTrue(shouldBeTrue) // expects above function to have returned
}
louiscad
02/05/2021, 4:43 PMKris Wong
02/05/2021, 4:46 PM./gradlew testDebugUnitTest
. it's a common test and passes on iOS, and also when run in the IDE.louiscad
02/05/2021, 4:46 PMKris Wong
02/05/2021, 4:47 PMHttpClient().post
louiscad
02/05/2021, 4:48 PMKris Wong
02/05/2021, 4:48 PMwasyl
02/05/2021, 4:49 PMsomeSuspendingFunction
does thing asynchronously, launches a coroutine in a separate scope for example. And the test is simply flaky, sometimes the asynchronous thing manages to complete and sometimes it doesn’tKris Wong
02/05/2021, 4:49 PMwasyl
02/05/2021, 4:51 PMI’m not quite sure how to fix itIt really depends on what
someSuspendingFunction()
doeslouiscad
02/05/2021, 4:51 PMKris Wong
02/05/2021, 4:51 PMlouiscad
02/05/2021, 4:53 PMKris Wong
02/05/2021, 4:55 PMlouiscad
02/05/2021, 4:55 PMKris Wong
02/05/2021, 4:56 PMwithContext
might do the trick, but I don't think that API is availablelouiscad
02/05/2021, 4:57 PMDispatchers.Default { }
, or just coroutineScope { }
if you fear you broke structured concurrency in a way or another at the immediate level.CoroutineScope
, it's very likely you're breaking structured concurrency BTW.Kris Wong
02/05/2021, 4:59 PMrunBlocking
, however I am sure Ktor is creating one or more scopeswithContext
didn't fix itlouiscad
02/05/2021, 4:59 PMKris Wong
02/05/2021, 5:14 PMlouiscad
02/05/2021, 5:15 PMKris Wong
02/05/2021, 5:17 PMrunBlocking
is working as expectedlouiscad
02/05/2021, 10:04 PMgildor
02/08/2021, 3:07 AMKris Wong
02/08/2021, 2:02 PMgildor
02/09/2021, 2:03 AMKris Wong
02/09/2021, 1:52 PMrunBlocking