kevin.cianfarini
06/10/2021, 7:43 PMexpected: Thread[test,5,main]
but was : Thread[main @coroutine#1,5,main]
uli
06/10/2021, 7:50 PMkevin.cianfarini
06/10/2021, 7:52 PMuli
06/10/2021, 7:52 PMThread.currentThread().getId()
kevin.cianfarini
06/10/2021, 7:53 PMexpected: 21
but was : 1
UNDISPATCHED
start. I have edited the source example to simplify it furtheruli
06/10/2021, 7:59 PMkevin.cianfarini
06/10/2021, 8:05 PMuli
06/10/2021, 8:07 PMkevin.cianfarini
06/10/2021, 8:08 PMrunBlocking
works.uli
06/10/2021, 8:30 PM@Test fun isolateFailing() = runBlocking(TestCoroutineDispatcher()) {
var outerThread: Thread? = nullThread.currentThread()
val singleThreadedContext = newSingleThreadContext("test")
var innerThread: Thread? = null
val function = suspend {
outerThread = Thread.currentThread()
innerThread = withContext(this@runBlocking.coroutineContext) {
Thread.currentThread()
}
}
val job = launch {
withContext(singleThreadedContext) {
function()
}
}
job.join()
assertThat(outerThread).isNotEqualTo(innerThread)
}
kevin.cianfarini
06/10/2021, 8:36 PMexpected not to be: Thread[test,5,main]
uli
06/10/2021, 8:39 PMkevin.cianfarini
06/10/2021, 9:01 PMAdam Powell
06/11/2021, 1:31 AM* By default, [TestCoroutineDispatcher] is immediate. That means any tasks scheduled to be run without delay are
* immediately executed. If they were scheduled with a delay, the virtual clock-time must be advanced via one of the
* methods on [DelayController].