restore parallel_cycle_mid_recover

This commit is contained in:
Niko Matsakis 2024-07-24 09:53:24 +00:00
parent 82d37de105
commit ac474a9c8d
3 changed files with 27 additions and 23 deletions

View file

@ -1,9 +1,7 @@
mod setup;
mod parallel_cycle_all_recover;
#[cfg(disabled)]
mod parallel_cycle_mid_recover;
#[cfg(disabled)]
mod parallel_cycle_none_recover;
#[cfg(disabled)]
mod parallel_cycle_one_recover;

View file

@ -2,6 +2,8 @@
//! See `../cycles.rs` for a complete listing of cycle tests,
//! both intra and cross thread.
use salsa::Handle;
use crate::setup::Database;
use crate::setup::Knobs;
@ -86,18 +88,18 @@ fn recover_b3(db: &dyn Db, _cycle: &salsa::Cycle, key: MyInput) -> i32 {
#[test]
fn execute() {
let db = Database::default();
db.knobs().signal_on_will_block.set(3);
let db = Handle::new(Database::default());
db.knobs().signal_on_will_block.store(3);
let input = MyInput::new(&db, 1);
let input = MyInput::new(&*db, 1);
let thread_a = std::thread::spawn({
let db = db.snapshot();
let db = db.clone();
move || a1(&*db, input)
});
let thread_b = std::thread::spawn({
let db = db.snapshot();
let db = db.clone();
move || b1(&*db, input)
});

View file

@ -5,6 +5,8 @@
use crate::setup::Database;
use crate::setup::Knobs;
use expect_test::expect;
use salsa::Database as _;
use salsa::Handle;
#[salsa::db]
pub(crate) trait Db: salsa::Database + Knobs {}
@ -41,35 +43,37 @@ pub(crate) fn b(db: &dyn Db, input: MyInput) -> i32 {
#[test]
fn execute() {
let db = Database::default();
db.knobs().signal_on_will_block.set(3);
let db = Handle::new(Database::default());
db.knobs().signal_on_will_block.store(3);
let input = MyInput::new(&db, -1);
let input = MyInput::new(&*db, -1);
let thread_a = std::thread::spawn({
let db = db.snapshot();
let db = db.clone();
move || a(&*db, input)
});
let thread_b = std::thread::spawn({
let db = db.snapshot();
let db = db.clone();
move || b(&*db, input)
});
// We expect B to panic because it detects a cycle (it is the one that calls A, ultimately).
// Right now, it panics with a string.
let err_b = thread_b.join().unwrap_err();
if let Some(c) = err_b.downcast_ref::<salsa::Cycle>() {
let expected = expect![[r#"
[
"a(0)",
"b(0)",
]
"#]];
expected.assert_debug_eq(&c.all_participants(&db));
} else {
panic!("b failed in an unexpected way: {:?}", err_b);
}
db.attach(|_| {
if let Some(c) = err_b.downcast_ref::<salsa::Cycle>() {
let expected = expect![[r#"
[
a(0),
b(0),
]
"#]];
expected.assert_debug_eq(&c.all_participants(&*db));
} else {
panic!("b failed in an unexpected way: {:?}", err_b);
}
});
// We expect A to propagate a panic, which causes us to use the sentinel
// type `Canceled`.