Skip to content

Commit 88c686d

Browse files
committed
add test for panic in cycle recovery function
1 parent aa7e4a4 commit 88c686d

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

tests/parallel/cycle_panic.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//! Test for panic in cycle recovery function, in cross-thread cycle.
2+
use crate::setup::{Knobs, KnobsDatabase};
3+
4+
#[salsa::tracked(cycle_fn=cycle_fn, cycle_initial=initial)]
5+
fn query_a(db: &dyn KnobsDatabase) {
6+
db.signal(1);
7+
db.wait_for(2);
8+
query_b(db);
9+
}
10+
11+
#[salsa::tracked]
12+
fn query_b(db: &dyn KnobsDatabase) {
13+
db.wait_for(1);
14+
db.signal(2);
15+
query_a(db);
16+
}
17+
18+
fn cycle_fn(_db: &dyn KnobsDatabase, _value: &(), _count: u32) -> salsa::CycleRecoveryAction<()> {
19+
panic!("cancel!")
20+
}
21+
22+
fn initial(_db: &dyn KnobsDatabase) {}
23+
24+
#[test]
25+
fn execute() {
26+
let db = Knobs::default();
27+
28+
std::thread::scope(|scope| {
29+
let db_t1 = db.clone();
30+
let thread_a = scope.spawn(move || query_a(&db_t1));
31+
32+
let db_t2 = db.clone();
33+
let thread_b = scope.spawn(move || query_b(&db_t2));
34+
35+
// The main thing here is that we don't deadlock.
36+
assert!(thread_a.join().is_err());
37+
assert!(thread_b.join().is_err());
38+
});
39+
}

tests/parallel/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod setup;
33
mod cycle_a_t1_b_t2;
44
mod cycle_ab_peeping_c;
55
mod cycle_nested_three_threads;
6+
mod cycle_panic;
67
mod parallel_cancellation;
78
mod parallel_map;
89
mod signal;

tests/parallel/parallel_cancellation.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
//! Test for cycle recover spread across two threads.
2-
//! See `../cycles.rs` for a complete listing of cycle tests,
3-
//! both intra and cross thread.
1+
//! Test for thread cancellation.
42
53
use salsa::Cancelled;
64
use salsa::Setter;

0 commit comments

Comments
 (0)