add red-herring tests which modify distinct inputs

This commit is contained in:
Niko Matsakis 2022-08-07 00:32:56 -04:00
parent 9ff6fb3376
commit 00172efb19
2 changed files with 52 additions and 1 deletions

View file

@ -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#"
[]"#]]);
}

View file

@ -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#"
[
]"#]]);
}