-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #734 from Veykril/veykril/push-txytyxrsumuu
Add test for durability changes
- Loading branch information
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//! Tests that code using the builder's durability methods compiles. | ||
use salsa::{Database, Durability, Setter}; | ||
use test_log::test; | ||
|
||
#[salsa::input] | ||
struct N { | ||
value: u32, | ||
} | ||
|
||
#[salsa::tracked] | ||
fn add3(db: &dyn Database, a: N, b: N, c: N) -> u32 { | ||
add(db, a, b) + c.value(db) | ||
} | ||
|
||
#[salsa::tracked] | ||
fn add(db: &dyn Database, a: N, b: N) -> u32 { | ||
a.value(db) + b.value(db) | ||
} | ||
|
||
#[test] | ||
fn durable_to_less_durable() { | ||
let mut db = salsa::DatabaseImpl::new(); | ||
|
||
let a = N::builder(11).value_durability(Durability::HIGH).new(&db); | ||
let b = N::builder(22).value_durability(Durability::HIGH).new(&db); | ||
let c = N::builder(33).value_durability(Durability::HIGH).new(&db); | ||
|
||
// Here, `add3` invokes `add(a, b)`, which yields 33. | ||
assert_eq!(add3(&db, a, b, c), 66); | ||
|
||
a.set_value(&mut db).with_durability(Durability::LOW).to(11); | ||
|
||
// Here, `add3` invokes `add`, which *still* yields 33, but which | ||
// is no longer of high durability. Since value didn't change, we might | ||
// preserve `add3` unchanged, not noticing that it is no longer | ||
// of high durability. | ||
|
||
assert_eq!(add3(&db, a, b, c), 66); | ||
|
||
// In that case, we would not get the correct result here, when | ||
// 'a' changes *again*. | ||
|
||
a.set_value(&mut db).to(22); | ||
|
||
assert_eq!(add3(&db, a, b, c), 77); | ||
} |