Skip to content

Commit 6e17452

Browse files
committed
Add test for multi-threaded usage with rayon
1 parent ef1e8d1 commit 6e17452

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@ required-features = ["rayon"]
4545
[[test]]
4646
name = "rayon-1"
4747
required-features = ["rayon"]
48+
49+
[[test]]
50+
name = "rayon-2"
51+
required-features = ["rayon"]

tests/rayon-2.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//! Must be a separate test because it modifies the _global_ rayon pool.
2+
use std::{fs::File, path::Path};
3+
use jpeg_decoder::Decoder;
4+
5+
#[test]
6+
fn decoding_in_global_pool() {
7+
let path = Path::new("tests/reftest/images/progressive3.jpg");
8+
9+
rayon::ThreadPoolBuilder::new()
10+
.num_threads(2)
11+
.build_global()
12+
.unwrap();
13+
14+
let _: Vec<_> = (0..1024)
15+
.map(|_| {
16+
let path = path.clone();
17+
std::thread::spawn(move || {
18+
let mut decoder = Decoder::new(File::open(&path).unwrap());
19+
let _ = decoder.decode().unwrap();
20+
});
21+
}).collect();
22+
}
23+

0 commit comments

Comments
 (0)