Skip to content

Commit

Permalink
Fix from_local_fn() test to take into account different behavior in s…
Browse files Browse the repository at this point in the history
…ingle/multi-threaded mode
  • Loading branch information
Bromeon committed Dec 8, 2024
1 parent 4028444 commit dbde40f
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions itest/rust/src/builtin_tests/containers/callable_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down

0 comments on commit dbde40f

Please sign in to comment.