2019-01-12 10:11:59 +00:00
|
|
|
use crate::setup::{InputQuery, ParDatabase, ParDatabaseImpl};
|
2018-10-13 09:24:34 +00:00
|
|
|
use salsa::{Database, ParallelDatabase};
|
|
|
|
|
|
|
|
/// 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-12 10:11:59 +00:00
|
|
|
db.query_mut(InputQuery).set('a', 100);
|
|
|
|
db.query_mut(InputQuery).set('b', 010);
|
|
|
|
db.query_mut(InputQuery).set('c', 001);
|
|
|
|
db.query_mut(InputQuery).set('d', 200);
|
|
|
|
db.query_mut(InputQuery).set('e', 020);
|
|
|
|
db.query_mut(InputQuery).set('f', 002);
|
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")
|
|
|
|
});;
|
2018-10-13 09:24:34 +00:00
|
|
|
|
|
|
|
assert_eq!(thread1.join().unwrap(), 111);
|
|
|
|
assert_eq!(thread2.join().unwrap(), 222);
|
|
|
|
}
|