From dbde40f21ba45c09008ec869e55b9af19766d3f1 Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Sun, 8 Dec 2024 16:07:08 +0100 Subject: [PATCH] Fix from_local_fn() test to take into account different behavior in single/multi-threaded mode --- .../builtin_tests/containers/callable_test.rs | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/itest/rust/src/builtin_tests/containers/callable_test.rs b/itest/rust/src/builtin_tests/containers/callable_test.rs index 73362f41d..981c57e41 100644 --- a/itest/rust/src/builtin_tests/containers/callable_test.rs +++ b/itest/rust/src/builtin_tests/containers/callable_test.rs @@ -195,7 +195,6 @@ pub mod custom_callable { } // Without this feature, any access to the global binding from another thread fails; so the from_local_fn() cannot be tested in isolation. - // #[cfg(feature = "experimental-threads")] #[itest] fn callable_from_local_fn_crossthread() { // This static is a workaround for not being able to propagate failed `Callable` invocations as panics. @@ -212,17 +211,29 @@ pub mod custom_callable { let crosser = ThreadCrosser::new(callable); // Create separate thread and ensure calling fails. - // expect_panic( - // "Callable created with from_local_fn() must panic when invoked on other thread", - // ||{ + // Why expect_panic for single-threaded but not multi-threaded mode: + // - We currently can't catch panics from Callable invocations, see above. True for both single/multi. + // - In single-threaded mode, there's an FFI access check which panics as soon as another thread is invoked. + // *This* panics. + // - In multi-threaded, we need to observe the effect instead (see below). + + #[cfg(not(feature = "experimental-threads"))] + crate::framework::expect_panic( + "Callable created with from_local_fn() must panic when invoked on other thread", + || { + quick_thread(|| { + let callable = unsafe { crosser.extract() }; + callable.callv(&varray![5]); + }); + }, + ); + + #[cfg(feature = "experimental-threads")] quick_thread(|| { let callable = unsafe { crosser.extract() }; callable.callv(&varray![5]); }); - // ,); - // We should really use expect_panic here (AROUND quick_thread, not inside), however we currently can't catch panics, see above. - // Instead, we check the global value. assert_eq!( *GLOBAL.lock(), 0,