Module proptest_types

Source
Available on crate feature proptest1 only.
Expand description

Proptest support for partial IO operations.

This module allows sequences of PartialOps to be randomly generated. These sequences can then be fed into a PartialRead, PartialWrite, PartialAsyncRead or PartialAsyncWrite.

Once proptest has identified a failing test case, it will shrink the sequence of PartialOps and find a minimal test case. This minimal case can then be used to reproduce the issue.

Basic implementations are provided for:

  • generating errors some of the time
  • generating PartialOp instances, given a way to generate errors.

§Examples

use partial_io::proptest_types::{partial_op_strategy, interrupted_strategy};
use proptest::{collection::vec, prelude::*};

proptest! {
    #[test]
    fn proptest_something(ops: vec(partial_op_strategy(interrupted_strategy(), 128), 0..128)) {
        // Example buffer to read from, substitute with your own.
        let reader = std::io::repeat(42);
        let partial_reader = PartialRead::new(reader, ops);
        // ...

        true
    }
}

For a detailed example, see examples/buggy_write.rs in this repository.

Functions§

interrupted_strategy
Returns a strategy that generates Interrupted errors 20% of the time.
interrupted_would_block_strategy
Returns a strategy that generates Interrupted errors 10% of the time and WouldBlock errors 10% of the time.
partial_op_strategy
Returns a strategy that generates PartialOp instances given a way to generate errors.
would_block_strategy
Returns a strategy that generates WouldBlock errors 20% of the time.