You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to update my coroutines tests to use runTest instead of runBlocking.
The code under test causes the TestScope to be frozen (which is expected) resulting in the following InvalidMutabilityException:
kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlinx.coroutines.internal.ThreadSafeHeap@52a0d8
at kotlin.Throwable#<init>(/opt/buildAgent/work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Throwable.kt:24)
at kotlin.Exception#<init>(/opt/buildAgent/work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:23)
at kotlin.RuntimeException#<init>(/opt/buildAgent/work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:34)
at kotlin.native.concurrent.InvalidMutabilityException#<init>(/opt/buildAgent/work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/native/concurrent/Freezing.kt:24)
at <global>.ThrowInvalidMutabilityException(/opt/buildAgent/work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:109)
at <global>.MutationCheck(Unknown Source)
at kotlinx.coroutines.internal.ThreadSafeHeap.<set-a>#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/ThreadSafeHeap.kt:26)
at kotlinx.coroutines.internal.ThreadSafeHeap.realloc#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/ThreadSafeHeap.kt:145)
at kotlinx.coroutines.internal.ThreadSafeHeap#addImpl(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Debug.kt:17)
at kotlinx.coroutines.internal.ThreadSafeHeap#addLast(/opt/buildAgent/work/88b0986a7186d029/atomicfu/src/nativeMain/kotlin/kotlinx/atomicfu/locks/Synchronized.kt:38)
at kotlinx.coroutines.test.TestCoroutineScheduler#registerEvent(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestCoroutineScheduler.kt:72)
at kotlinx.coroutines.test.StandardTestDispatcherImpl.dispatch#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestCoroutineDispatchers.kt:155)
at kotlinx.coroutines.internal#resumeCancellableWith__at__kotlin.coroutines.Continuation<0:0>(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/DispatchedContinuation.kt:282)
at kotlinx.coroutines.intrinsics#startCoroutineCancellable__at__kotlin.coroutines.SuspendFunction1<0:0,0:1>(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/intrinsics/Cancellable.kt:30)
at kotlinx.coroutines#startCoroutineImpl(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/Builders.common.kt:192)
at kotlinx.coroutines.startCoroutine#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Builders.kt:147)
at kotlinx.coroutines#startAbstractCoroutine(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Builders.kt:118)
at kotlinx.coroutines.AbstractCoroutine#start(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/AbstractCoroutine.kt:130)
at kotlinx.coroutines#launch__at__kotlinx.coroutines.CoroutineScope(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/Builders.common.kt:56)
at kotlinx.coroutines#launch$default__at__kotlinx.coroutines.CoroutineScope(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/Builders.common.kt:47)
@Test
fun`ensure completion callback is invoked`() = runBlocking {
val flow = flow<RandomValue> { }
val job =Job()
val nativeFlow = flow.asNativeFlow(CoroutineScope(job))
val completionCount =AtomicInt(0)
nativeFlow({ _, _ -> }, { error, _ ->
assertNull(error, "Flow should complete without an error")
completionCount.increment()
})
job.children.forEach { it.join() } // Waits for the collection to complete
assertEquals(1, completionCount.value, "Completion callback should be called once")
}
converting it to use runTest like this results in the InvalidMutabilityException:
@Test
fun`ensure completion callback is invoked`() = runTest {
val flow = flow<RandomValue> { }
val nativeFlow = flow.asNativeFlow(this)
val completionCount =AtomicInt(0)
nativeFlow({ _, _ -> }, { error, _ ->
assertNull(error, "Flow should complete without an error")
completionCount.increment()
})
runCurrent()
assertEquals(1, completionCount.value, "Completion callback should be called once")
}
The text was updated successfully, but these errors were encountered:
NativeFlow.kt is what we end up freezing so it can be freely moved across threads. When migrating to runTest, we this freezes TestCoroutineScope and causes this issue
AppleNativeFlowTests.kt use the runBlocking approach and are passing.
NativeFlowTests.kt use the runTest approach and are failing on Native platforms due to the freezing issue.
I am trying to update my coroutines tests to use
runTest
instead ofrunBlocking
.The code under test causes the
TestScope
to be frozen (which is expected) resulting in the followingInvalidMutabilityException
:The old code looks like this:
converting it to use
runTest
like this results in theInvalidMutabilityException
:The text was updated successfully, but these errors were encountered: