Sha256: 2ca857b37b740528b2e8395b479a409227383b46e0ed012286dcdd1330dacd70

Contents?: true

Size: 1.65 KB

Versions: 33

Compression:

Stored size: 1.65 KB

Contents

use rayon::prelude::*;
use rayon::ThreadPoolBuilder;
use std::ops::Range;
use std::panic::{self, UnwindSafe};
use std::sync::atomic::{AtomicUsize, Ordering};

const ITER: Range<i32> = 0..0x1_0000;
const PANIC: i32 = 0xC000;

fn check(&i: &i32) {
    if i == PANIC {
        panic!("boom")
    }
}

#[test]
#[should_panic(expected = "boom")]
fn iter_panic() {
    ITER.into_par_iter().for_each(|i| check(&i));
}

#[test]
#[cfg_attr(not(panic = "unwind"), ignore)]
fn iter_panic_fuse() {
    // We only use a single thread in order to make the behavior
    // of 'panic_fuse' deterministic
    let pool = ThreadPoolBuilder::new().num_threads(1).build().unwrap();

    pool.install(|| {
        fn count(iter: impl ParallelIterator + UnwindSafe) -> usize {
            let count = AtomicUsize::new(0);
            let result = panic::catch_unwind(|| {
                iter.for_each(|_| {
                    count.fetch_add(1, Ordering::Relaxed);
                });
            });
            assert!(result.is_err());
            count.into_inner()
        }

        // Without `panic_fuse()`, we'll reach every item except the panicking one.
        let expected = ITER.len() - 1;
        let iter = ITER.into_par_iter().with_max_len(1);
        assert_eq!(count(iter.clone().inspect(check)), expected);

        // With `panic_fuse()` anywhere in the chain, we'll reach fewer items.
        assert!(count(iter.clone().inspect(check).panic_fuse()) < expected);
        assert!(count(iter.clone().panic_fuse().inspect(check)) < expected);

        // Try in reverse to be sure we hit the producer case.
        assert!(count(iter.panic_fuse().inspect(check).rev()) < expected);
    });
}

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/rayon-1.10.0/tests/iter_panic.rs
wasmtime-28.0.0 ./ext/cargo-vendor/rayon-1.10.0/tests/iter_panic.rs
wasmtime-27.0.0 ./ext/cargo-vendor/rayon-1.10.0/tests/iter_panic.rs
wasmtime-26.0.0 ./ext/cargo-vendor/rayon-1.10.0/tests/iter_panic.rs
wasmtime-25.0.2 ./ext/cargo-vendor/rayon-1.10.0/tests/iter_panic.rs
wasmtime-25.0.1 ./ext/cargo-vendor/rayon-1.10.0/tests/iter_panic.rs
wasmtime-25.0.0 ./ext/cargo-vendor/rayon-1.10.0/tests/iter_panic.rs
wasmtime-24.0.0 ./ext/cargo-vendor/rayon-1.10.0/tests/iter_panic.rs
wasmtime-23.0.2 ./ext/cargo-vendor/rayon-1.8.0/tests/iter_panic.rs
wasmtime-22.0.0 ./ext/cargo-vendor/rayon-1.8.0/tests/iter_panic.rs
wasmtime-21.0.1 ./ext/cargo-vendor/rayon-1.8.0/tests/iter_panic.rs
wasmtime-20.0.2 ./ext/cargo-vendor/rayon-1.8.0/tests/iter_panic.rs
wasmtime-20.0.0 ./ext/cargo-vendor/rayon-1.8.0/tests/iter_panic.rs
wasmtime-18.0.3 ./ext/cargo-vendor/rayon-1.8.0/tests/iter_panic.rs
wasmtime-17.0.1 ./ext/cargo-vendor/rayon-1.8.0/tests/iter_panic.rs
wasmtime-17.0.0 ./ext/cargo-vendor/rayon-1.8.0/tests/iter_panic.rs
wasmtime-16.0.0 ./ext/cargo-vendor/rayon-1.8.0/tests/iter_panic.rs
wasmtime-15.0.1 ./ext/cargo-vendor/rayon-1.8.0/tests/iter_panic.rs
wasmtime-15.0.0 ./ext/cargo-vendor/rayon-1.8.0/tests/iter_panic.rs
wasmtime-14.0.4 ./ext/cargo-vendor/rayon-1.8.0/tests/iter_panic.rs