Change loom tests to use cfg(loom) internally (#314)

This commit is contained in:
Sean McArthur
2019-11-13 14:55:25 -08:00
committed by GitHub
parent b32f6298e2
commit 9a10addb44
6 changed files with 94 additions and 73 deletions
+33
View File
@@ -903,3 +903,36 @@ unsafe fn release_shared(ptr: *mut Shared) {
// Drop the data
Box::from_raw(ptr);
}
// fuzz tests
#[cfg(all(test, loom))]
mod fuzz {
use std::sync::Arc;
use loom::thread;
use super::Bytes;
#[test]
fn bytes_cloning_vec() {
loom::model(|| {
let a = Bytes::from(b"abcdefgh".to_vec());
let addr = a.as_ptr() as usize;
// test the Bytes::clone is Sync by putting it in an Arc
let a1 = Arc::new(a);
let a2 = a1.clone();
let t1 = thread::spawn(move || {
let b: Bytes = (*a1).clone();
assert_eq!(b.as_ptr() as usize, addr);
});
let t2 = thread::spawn(move || {
let b: Bytes = (*a2).clone();
assert_eq!(b.as_ptr() as usize, addr);
});
t1.join().unwrap();
t2.join().unwrap();
});
}
}