Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions wasm-core/jvmTest/wasm/core/SnapshotSuspensionSafetyJvmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -56,6 +57,16 @@ class SnapshotSuspensionSafetyJvmTest {
instance.invoke("resume")
}
store.status.first { it == StoreStatus.InHostImport }
// InHostImport is published before the import's continuation
// parks. A capture probe only succeeds once the running segment
// has suspended and released the execution gate, so poll it to
// guarantee the completion below resumes a parked continuation
// on the resumer thread instead of finishing the await inline.
withTimeout(5_000) {
while (runCatching { store.captureSnapshotState(instance) }.isFailure) {
delay(1)
}
}
assertFalse(invocation.isCompleted)

withContext(resumerDispatcher) {
Expand Down Expand Up @@ -112,6 +123,10 @@ class SnapshotSuspensionSafetyJvmTest {
try {
val invocation = async(invocationDispatcher) { instance.invoke("wait") }
store.status.first { it == StoreStatus.InHostImport }
// InHostImport is published before host code runs. Drain the
// single-thread dispatcher to prove that the host continuation
// has actually suspended and released the store execution gate.
withContext(invocationDispatcher) { Unit }

val captureStarted = CountDownLatch(1)
val finishCapture = CountDownLatch(1)
Expand Down
Loading