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);
|
|
|
|
db.set_input('b', 010);
|
|
|
|
db.set_input('c', 001);
|
|
|
|
db.set_input('d', 200);
|
|
|
|
db.set_input('e', 020);
|
|
|
|
db.set_input('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);
|
|
|
|
}
|