[K/N][tests] Migrate various runtime/ tests ^KT-61259

This commit is contained in:
Alexander Shabalin
2024-03-11 22:48:50 +01:00
committed by Space Team
parent 7ad4e58a7a
commit d88092aa94
99 changed files with 2102 additions and 1905 deletions
@@ -0,0 +1,19 @@
// OUTPUT_REGEX: ^$
@file:OptIn(FreezingIsDeprecated::class, ObsoleteWorkersApi::class)
import kotlin.test.*
import kotlin.native.concurrent.*
// Ensure that termination of current worker on main thread doesn't lead to problems.
fun main() {
val worker = Worker.current
val future = worker.requestTermination(false)
worker.processQueue()
assertEquals(future.state, FutureState.COMPUTED)
future.consume {}
// After termination request this worker is no longer addressable.
assertFailsWith<IllegalStateException> { worker.executeAfter(0, {
println("BUG!")
})}
}
@@ -0,0 +1,14 @@
// EXIT_CODE: !0
// OUTPUT_REGEX: .*an error.*
// OUTPUT_REGEX: (?!.*Will not happen.*).*
import kotlin.test.*
import kotlin.native.concurrent.*
fun main() {
Worker.current.executeAfter(0L, {
throw Error("an error")
})
Worker.current.processQueue()
println("Will not happen")
}
@@ -0,0 +1,18 @@
// No termination is going on here. But that's the closest location to other unhandled exception hook tests.
// KIND: REGULAR
// OUTPUT_REGEX: hook called\R
import kotlin.test.*
import kotlin.native.concurrent.*
@OptIn(kotlin.experimental.ExperimentalNativeApi::class)
@Test
fun testExecuteAfterStartQuiet() {
setUnhandledExceptionHook {
println("hook called")
}
Worker.current.executeAfter(0L, {
throw Error("an error")
})
Worker.current.processQueue()
}
@@ -0,0 +1,18 @@
// No termination is going on here. But that's the closest location to other unhandled exception hook tests.
// KIND: REGULAR
// OUTPUT_REGEX: .*an error.*
import kotlin.test.*
import kotlin.native.concurrent.*
@Test
fun testExecuteStart() {
val worker = Worker.start()
val future = worker.execute(TransferMode.SAFE, {}) {
throw Error("an error")
}
assertFailsWith<Throwable> {
future.result
}
worker.requestTermination().result
}
@@ -0,0 +1,15 @@
// EXIT_CODE: !0
// OUTPUT_REGEX: .*an error.*
// OUTPUT_REGEX: (?!.*Will not happen.*).*
import kotlin.test.*
import kotlin.native.concurrent.*
fun main() {
val worker = Worker.start()
worker.executeAfter(0L, {
throw Error("an error")
})
worker.requestTermination().result
println("Will not happen")
}
@@ -0,0 +1,15 @@
// No termination is going on here. But that's the closest location to other unhandled exception hook tests.
// KIND: REGULAR
// OUTPUT_REGEX: (?!.*an error.*)
import kotlin.test.*
import kotlin.native.concurrent.*
@Test
fun testExecuteAfterStartQuiet() {
val worker = Worker.start(errorReporting = false)
worker.executeAfter(0L, {
throw Error("an error")
})
worker.requestTermination().result
}
@@ -0,0 +1,19 @@
// No termination is going on here. But that's the closest location to other unhandled exception hook tests.
// KIND: REGULAR
// OUTPUT_REGEX: hook called\R
import kotlin.test.*
import kotlin.native.concurrent.*
@OptIn(kotlin.experimental.ExperimentalNativeApi::class)
@Test
fun testExecuteAfterStartQuiet() {
setUnhandledExceptionHook {
println("hook called")
}
val worker = Worker.start()
worker.executeAfter(0L, {
throw Error("an error")
})
worker.requestTermination().result
}
@@ -0,0 +1,18 @@
// No termination is going on here. But that's the closest location to other unhandled exception hook tests.
// KIND: REGULAR
// OUTPUT_REGEX: (?!.*an error.*)
import kotlin.test.*
import kotlin.native.concurrent.*
@Test
fun testExecuteStartQuiet() {
val worker = Worker.start(errorReporting = false)
val future = worker.execute(TransferMode.SAFE, {}) {
throw Error("an error")
}
assertFailsWith<Throwable> {
future.result
}
worker.requestTermination().result
}