#![allow(unexpected_cfgs)]
use dsfb_database::residual::{ResidualClass, ResidualSample, ResidualStream};
#[cfg(loom)]
use loom::sync::Arc;
#[cfg(loom)]
use loom::thread;
#[cfg(not(loom))]
use std::sync::Arc;
#[cfg(not(loom))]
use std::thread;
fn build_stream() -> ResidualStream {
let mut s = ResidualStream::new("loom-fixture");
for i in 0..16 {
s.push(ResidualSample::new(
i as f64,
ResidualClass::Cardinality,
(i as f64) * 0.1,
));
}
s.sort();
s
}
#[cfg(loom)]
#[test]
fn concurrent_readers_observe_consistent_length() {
loom::model(|| {
let stream = Arc::new(build_stream());
let stream_a = stream.clone();
let stream_b = stream.clone();
let handle_a = thread::spawn(move || stream_a.len());
let handle_b = thread::spawn(move || stream_b.len());
let len_a = handle_a.join().unwrap();
let len_b = handle_b.join().unwrap();
assert_eq!(len_a, 16);
assert_eq!(len_b, 16);
assert_eq!(len_a, len_b);
});
}
#[cfg(not(loom))]
#[test]
fn concurrent_readers_observe_consistent_length() {
let stream = Arc::new(build_stream());
let stream_a = stream.clone();
let stream_b = stream.clone();
let handle_a = thread::spawn(move || stream_a.len());
let handle_b = thread::spawn(move || stream_b.len());
let len_a = handle_a.join().unwrap();
let len_b = handle_b.join().unwrap();
assert_eq!(len_a, 16);
assert_eq!(len_b, 16);
assert_eq!(len_a, len_b);
}