1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
// Shuttle doesn't like panics inside of its runtime.
#![cfg(not(feature = "shuttle"))]
//! Test for thread cancellation.
use salsa::{Cancelled, Setter};
use crate::setup::{Knobs, KnobsDatabase};
#[salsa::input(debug)]
struct MyInput {
field: i32,
}
#[salsa::tracked]
fn a1(db: &dyn KnobsDatabase, input: MyInput) -> MyInput {
db.signal(1);
db.wait_for(2);
dummy(db, input)
}
#[salsa::tracked]
fn dummy(_db: &dyn KnobsDatabase, _input: MyInput) -> MyInput {
panic!("should never get here!")
}
// Cancellation signalling test
//
// The pattern is as follows.
//
// Thread A Thread B
// -------- --------
// a1
// | wait for stage 1
// signal stage 1 set input, triggers cancellation
// wait for stage 2 (blocks) triggering cancellation sends stage 2
// |
// (unblocked)
// dummy
// panics
#[test]
fn execute() {
let mut db = Knobs::default();
let input = MyInput::new(&db, 1);
let thread_a = std::thread::spawn({
let db = db.clone();
move || a1(&db, input)
});
db.signal_on_did_cancel(2);
input.set_field(&mut db).to(2);
// Assert thread A *should* was cancelled
let cancelled = thread_a
.join()
.unwrap_err()
.downcast::<Cancelled>()
.unwrap();
// and inspect the output
expect_test::expect![[r#"
PendingWrite
"#]]
.assert_debug_eq(&cancelled);
}
|