add test_share_reader
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Dmitry Belyaev 2023-03-28 15:43:08 +03:00
parent 3a26a4aa7f
commit 8120a996a3
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3

View File

@ -504,4 +504,40 @@ mod test {
assert_eq!(pair.0, pair.1); assert_eq!(pair.0, pair.1);
}); });
} }
/// sharing Reader instance between threads
#[test]
fn test_share_reader() {
use std::thread;
let dir = tempdir().expect("tempdir");
let tmpfile = dir.path().join("test.tmp");
let opts = WriterOpts {
compress_lvl: 1,
data_buf_size: 10 * 1024 * 1024,
out_buf_size: 10 * 1024 * 1024,
current_buf_size: 4096,
};
let mut writer: Writer<TestData> = Writer::new(&tmpfile, opts).expect("new writer");
let items_iter = gen_data(10);
let items: Vec<TestData> = items_iter.collect();
writer.load(&mut items.clone().into_iter()).expect("load");
writer.finish().expect("finish write");
let reader: Reader<TestData> = Reader::new(&tmpfile, 2048).expect("new reader");
assert_eq!(items.len(), reader.len());
let reader = Arc::new(reader);
for _ in 0..=3 {
let cur_items = items.clone();
let cur_reader = Arc::clone(&reader);
thread::spawn(move || {
cur_items.into_iter().zip(cur_reader.iter()).for_each(|pair| {
assert_eq!(pair.0, pair.1);
});
});
}
}
} }