2019-01-27 21:06:14 +00:00
|
|
|
use crate::setup::{ParDatabase, ParDatabaseImpl};
|
|
|
|
use salsa::ParallelDatabase;
|
2018-10-13 09:24:34 +00:00
|
|
|
|
|
|
|
/// Test two `sum` queries (on distinct keys) executing in different
|
2018-11-01 00:05:31 +00:00
|
|
|
/// threads. Really just a test that `snapshot` etc compiles.
|
2018-10-13 09:24:34 +00:00
|
|
|
#[test]
|
|
|
|
fn in_par_two_independent_queries() {
|
2018-11-01 08:30:54 +00:00
|
|
|
let mut db = ParDatabaseImpl::default();
|
2018-10-13 09:24:34 +00:00
|
|
|
|
2019-01-27 21:06:14 +00:00
|
|
|
db.set_input('a', 100);
|
2021-06-03 11:12:38 +00:00
|
|
|
db.set_input('b', 10);
|
|
|
|
db.set_input('c', 1);
|
2019-01-27 21:06:14 +00:00
|
|
|
db.set_input('d', 200);
|
2021-06-03 11:12:38 +00:00
|
|
|
db.set_input('e', 20);
|
|
|
|
db.set_input('f', 2);
|
2018-10-13 09:24:34 +00:00
|
|
|
|
2018-10-31 16:01:36 +00:00
|
|
|
let thread1 = std::thread::spawn({
|
2018-11-01 00:05:31 +00:00
|
|
|
let db = db.snapshot();
|
2018-10-31 16:01:36 +00:00
|
|
|
move || db.sum("abc")
|
|
|
|
});
|
2018-10-13 09:24:34 +00:00
|
|
|
|
2018-10-31 16:01:36 +00:00
|
|
|
let thread2 = std::thread::spawn({
|
2018-11-01 00:05:31 +00:00
|
|
|
let db = db.snapshot();
|
2018-10-31 16:01:36 +00:00
|
|
|
move || db.sum("def")
|
2019-02-03 19:10:49 +00:00
|
|
|
});
|
2018-10-13 09:24:34 +00:00
|
|
|
|
|
|
|
assert_eq!(thread1.join().unwrap(), 111);
|
|
|
|
assert_eq!(thread2.join().unwrap(), 222);
|
|
|
|
}
|