Sebastian Schuberth
11/19/2024, 3:49 PMwuthTimeout
is not able to break out of this?Sebastian Schuberth
11/19/2024, 4:01 PMSebastian Schuberth
11/19/2024, 4:04 PMblockingTest = true
as described here also didn't work.Oliver.O
11/19/2024, 4:19 PMblockingTest
is, it is interrupting and shutting down an entire thread. You cannot use withTimeout
in this scenario, but you must use Kotest's timeout
parameter for the test in question. Did you try that?Klitos Kyriacou
11/19/2024, 4:25 PMclass MyTest : FreeSpec({
"test".config(blockingTest = true, timeout = 1.seconds) {
while (true) {} // Does not time out!
}
}
Sebastian Schuberth
11/19/2024, 4:33 PMDid you try that?Yes, I did. As @Klitos Kyriacou points out, it does not work.
Oliver.O
11/19/2024, 4:38 PMThread.interrupt
just sets an "interrupt status" flag. This flag is checked at specific execution points, see the docs and this Stack Overflow answer.Sebastian Schuberth
11/19/2024, 4:39 PMSebastian Schuberth
11/19/2024, 4:39 PMOliver.O
11/19/2024, 4:40 PMKlitos Kyriacou
11/19/2024, 4:50 PMSebastian Schuberth
11/19/2024, 5:02 PMOliver.O
11/19/2024, 5:18 PMThread.interrupt
?:
Unfortunately, there really isn't any technique that works in general. It should be noted that in all situations where a waiting thread doesn't respond toSo basically there is no practical and safe way of preemptive termination in today's modern concurrent architectures. Preemptive termination could always affect other parts of concurrently running code, making it inherently unsafe and almost impossible to get right. So we should all aim for cooperative cancellation and instrument CPU-bound code with interception points, where we could respond to cancellation requests and/or do some health checks to avoid logic errors leading to non-terminating execution or other forms of excessive resource consumption., it wouldn't respond toThread.interrupt
either.Thread.stop