Skip to content

Commit

Permalink
add test for panic in cycle recovery function
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed Mar 4, 2025
1 parent aa7e4a4 commit 5b44fbe
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
42 changes: 42 additions & 0 deletions tests/parallel/cycle_panic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//! Test for panic in cycle recovery function, in cross-thread cycle.
use crate::setup::{Knobs, KnobsDatabase};

#[salsa::tracked(cycle_fn=cycle_fn, cycle_initial=initial)]
fn query_a(db: &dyn KnobsDatabase) -> u32 {
db.signal(1);
db.wait_for(2);
query_b(db)
}

#[salsa::tracked(cycle_fn=cycle_fn, cycle_initial=initial)]
fn query_b(db: &dyn KnobsDatabase) -> u32 {
db.wait_for(1);
db.signal(2);
query_a(db) + 1
}

fn cycle_fn(_db: &dyn KnobsDatabase, _value: &u32, _count: u32) -> salsa::CycleRecoveryAction<u32> {
panic!("cancel!")
}

fn initial(_db: &dyn KnobsDatabase) -> u32 {
0
}

#[test]
fn execute() {
let db = Knobs::default();

std::thread::scope(|scope| {
let db_t1 = db.clone();
let t1 = scope.spawn(move || query_a(&db_t1));

let db_t2 = db.clone();
let t2 = scope.spawn(move || query_b(&db_t2));

// The main thing here is that we don't deadlock.
let (r1, r2) = (t1.join(), t2.join());
assert!(r1.is_err());
assert!(r2.is_err());
});
}
1 change: 1 addition & 0 deletions tests/parallel/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod setup;
mod cycle_a_t1_b_t2;
mod cycle_ab_peeping_c;
mod cycle_nested_three_threads;
mod cycle_panic;
mod parallel_cancellation;
mod parallel_map;
mod signal;
4 changes: 1 addition & 3 deletions tests/parallel/parallel_cancellation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//! Test for cycle recover spread across two threads.
//! See `../cycles.rs` for a complete listing of cycle tests,
//! both intra and cross thread.
//! Test for thread cancellation.
use salsa::Cancelled;
use salsa::Setter;
Expand Down

0 comments on commit 5b44fbe

Please sign in to comment.