2018-10-25 12:41:26 +00:00
|
|
|
use crate::db;
|
2019-01-12 10:11:59 +00:00
|
|
|
use crate::group::{FibonacciQuery, GcDatabase};
|
2018-10-25 12:41:26 +00:00
|
|
|
use salsa::debug::DebugQueryTable;
|
2019-06-25 22:02:56 +00:00
|
|
|
use salsa::{Database, Durability, SweepStrategy};
|
2018-10-25 12:41:26 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sweep_default() {
|
2019-09-27 09:50:16 +00:00
|
|
|
let mut db = db::DatabaseImpl::default();
|
2018-10-25 12:41:26 +00:00
|
|
|
|
|
|
|
db.fibonacci(5);
|
|
|
|
|
2019-01-23 11:21:54 +00:00
|
|
|
let k: Vec<_> = db.query(FibonacciQuery).entries();
|
2018-10-25 12:41:26 +00:00
|
|
|
assert_eq!(k.len(), 6);
|
|
|
|
|
2019-09-27 09:50:16 +00:00
|
|
|
db.salsa_runtime_mut().synthetic_write(Durability::LOW);
|
2018-10-25 12:41:26 +00:00
|
|
|
|
|
|
|
db.fibonacci(5);
|
|
|
|
db.fibonacci(3);
|
|
|
|
|
|
|
|
// fibonacci is a constant, so it will not be invalidated,
|
|
|
|
// hence we keep 3 and 5 but remove the rest.
|
2019-01-27 14:14:57 +00:00
|
|
|
db.sweep_all(SweepStrategy::discard_outdated());
|
2019-01-23 11:21:54 +00:00
|
|
|
assert_keys! {
|
|
|
|
db,
|
|
|
|
FibonacciQuery => (3, 5),
|
|
|
|
}
|
2018-10-25 12:41:26 +00:00
|
|
|
|
|
|
|
// Even though we ran the sweep, 5 is still in cache
|
|
|
|
db.clear_log();
|
|
|
|
db.fibonacci(5);
|
|
|
|
db.assert_log(&[]);
|
|
|
|
|
|
|
|
// Same but we discard values this time.
|
2018-12-18 23:40:02 +00:00
|
|
|
db.sweep_all(
|
|
|
|
SweepStrategy::default()
|
|
|
|
.discard_values()
|
2019-01-27 14:14:57 +00:00
|
|
|
.sweep_all_revisions(),
|
2018-12-18 23:40:02 +00:00
|
|
|
);
|
2019-01-27 14:14:57 +00:00
|
|
|
db.sweep_all(SweepStrategy::discard_outdated());
|
2019-01-23 11:21:54 +00:00
|
|
|
assert_keys! {
|
|
|
|
db,
|
|
|
|
FibonacciQuery => (3, 5),
|
|
|
|
}
|
2018-10-25 12:41:26 +00:00
|
|
|
|
|
|
|
// Now we have to recompute
|
|
|
|
db.clear_log();
|
|
|
|
db.fibonacci(5);
|
|
|
|
db.assert_log(&[
|
|
|
|
"fibonacci(5)",
|
|
|
|
"fibonacci(4)",
|
|
|
|
"fibonacci(3)",
|
|
|
|
"fibonacci(2)",
|
|
|
|
"fibonacci(1)",
|
|
|
|
"fibonacci(0)",
|
|
|
|
]);
|
|
|
|
}
|