mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-02-02 09:46:06 +00:00
add red-herring tests which modify distinct inputs
This commit is contained in:
parent
9ff6fb3376
commit
00172efb19
2 changed files with 52 additions and 1 deletions
|
@ -83,3 +83,28 @@ fn execute() {
|
||||||
"final_result(MyInput(Id { value: 1 }))",
|
"final_result(MyInput(Id { value: 1 }))",
|
||||||
]"#]]);
|
]"#]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create and mutate a distinct input. No re-execution required.
|
||||||
|
#[test]
|
||||||
|
fn red_herring() {
|
||||||
|
let mut db = Database::default();
|
||||||
|
|
||||||
|
let input = MyInput::new(&mut db, 22);
|
||||||
|
assert_eq!(final_result(&db, input), 22);
|
||||||
|
db.assert_logs(expect![[r#"
|
||||||
|
[
|
||||||
|
"final_result(MyInput(Id { value: 1 }))",
|
||||||
|
"intermediate_result(MyInput(Id { value: 1 }))",
|
||||||
|
]"#]]);
|
||||||
|
|
||||||
|
// Create a distinct input and mutate it.
|
||||||
|
// This will trigger a new revision in the database
|
||||||
|
// but shouldn't actually invalidate our existing ones.
|
||||||
|
let input2 = MyInput::new(&mut db, 44);
|
||||||
|
input2.set_field(&mut db, 66);
|
||||||
|
|
||||||
|
// Re-run the query on the original input. Nothing re-executes!
|
||||||
|
assert_eq!(final_result(&db, input), 22);
|
||||||
|
db.assert_logs(expect![[r#"
|
||||||
|
[]"#]]);
|
||||||
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ impl HasLogger for Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute() {
|
fn one_entity() {
|
||||||
let mut db = Database::default();
|
let mut db = Database::default();
|
||||||
|
|
||||||
let input = MyInput::new(&mut db, 22);
|
let input = MyInput::new(&mut db, 22);
|
||||||
|
@ -85,3 +85,29 @@ fn execute() {
|
||||||
"final_result(MyInput(Id { value: 1 }))",
|
"final_result(MyInput(Id { value: 1 }))",
|
||||||
]"#]]);
|
]"#]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create and mutate a distinct input. No re-execution required.
|
||||||
|
#[test]
|
||||||
|
fn red_herring() {
|
||||||
|
let mut db = Database::default();
|
||||||
|
|
||||||
|
let input = MyInput::new(&mut db, 22);
|
||||||
|
assert_eq!(final_result(&db, input), 22);
|
||||||
|
db.assert_logs(expect![[r#"
|
||||||
|
[
|
||||||
|
"final_result(MyInput(Id { value: 1 }))",
|
||||||
|
"intermediate_result(MyInput(Id { value: 1 }))",
|
||||||
|
]"#]]);
|
||||||
|
|
||||||
|
// Create a distinct input and mutate it.
|
||||||
|
// This will trigger a new revision in the database
|
||||||
|
// but shouldn't actually invalidate our existing ones.
|
||||||
|
let input2 = MyInput::new(&mut db, 44);
|
||||||
|
input2.set_field(&mut db, 66);
|
||||||
|
|
||||||
|
// Re-run the query on the original input. Nothing re-executes!
|
||||||
|
assert_eq!(final_result(&db, input), 22);
|
||||||
|
db.assert_logs(expect![[r#"
|
||||||
|
[
|
||||||
|
]"#]]);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue