Skip to content

Commit 9656eb2

Browse files
committed
Fix from_local_fn() test re. different single/multi-thread panics
1 parent 6ea1629 commit 9656eb2

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

itest/rust/src/builtin_tests/containers/callable_test.rs

+24-11
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ pub mod custom_callable {
195195
}
196196

197197
// Without this feature, any access to the global binding from another thread fails; so the from_local_fn() cannot be tested in isolation.
198-
// #[cfg(feature = "experimental-threads")]
199198
#[itest]
200199
fn callable_from_local_fn_crossthread() {
201200
// This static is a workaround for not being able to propagate failed `Callable` invocations as panics.
@@ -212,17 +211,31 @@ pub mod custom_callable {
212211
let crosser = ThreadCrosser::new(callable);
213212

214213
// Create separate thread and ensure calling fails.
215-
// expect_panic(
216-
// "Callable created with from_local_fn() must panic when invoked on other thread",
217-
// ||{
218-
quick_thread(|| {
219-
let callable = unsafe { crosser.extract() };
220-
callable.callv(&varray![5]);
221-
});
222-
// ,);
214+
// Why expect_panic for (single-threaded && Debug) but not (multi-threaded || Release) mode:
215+
// - Check is only enabled in Debug, not Release.
216+
// - We currently can't catch panics from Callable invocations, see above. True for both single/multi-threaded.
217+
// - In single-threaded mode, there's an FFI access check which panics as soon as another thread is invoked. *This* panics.
218+
// - In multi-threaded, we need to observe the effect instead (see below).
219+
220+
if !cfg!(feature = "experimental-threads") && cfg!(debug_assertions) {
221+
// Single-threaded and Debug.
222+
crate::framework::expect_panic(
223+
"Callable created with from_local_fn() must panic when invoked on other thread",
224+
|| {
225+
quick_thread(|| {
226+
let callable = unsafe { crosser.extract() };
227+
callable.callv(&varray![5]);
228+
});
229+
},
230+
);
231+
} else {
232+
// Multi-threaded OR Release.
233+
quick_thread(|| {
234+
let callable = unsafe { crosser.extract() };
235+
callable.callv(&varray![5]);
236+
});
237+
}
223238

224-
// We should really use expect_panic here (AROUND quick_thread, not inside), however we currently can't catch panics, see above.
225-
// Instead, we check the global value.
226239
assert_eq!(
227240
*GLOBAL.lock(),
228241
0,

0 commit comments

Comments
 (0)