salsa/tests/parallel/independent.rs
Niko Matsakis b0171dbc11 remove fork_mut and adopt new strategy
Required simplifying the various tests.
2018-10-31 12:01:36 -04:00

29 lines
832 B
Rust

use crate::setup::{Input, ParDatabase, ParDatabaseImpl};
use salsa::{Database, ParallelDatabase};
/// Test two `sum` queries (on distinct keys) executing in different
/// threads. Really just a test that `fork` etc compiles.
#[test]
fn in_par_two_independent_queries() {
let db = ParDatabaseImpl::default();
db.query(Input).set('a', 100);
db.query(Input).set('b', 010);
db.query(Input).set('c', 001);
db.query(Input).set('d', 200);
db.query(Input).set('e', 020);
db.query(Input).set('f', 002);
let thread1 = std::thread::spawn({
let db = db.fork();
move || db.sum("abc")
});
let thread2 = std::thread::spawn({
let db = db.fork();
move || db.sum("def")
});;
assert_eq!(thread1.join().unwrap(), 111);
assert_eq!(thread2.join().unwrap(), 222);
}