Skip to main content

shrink

Function shrink 

Source
pub fn shrink<P>(
    scenario: &Scenario<P::Cmd>,
    predicate_name: &str,
    build: impl Fn(Config, &[NodeId]) -> Sim<P>,
    predicate: impl Fn(&Sim<P>) -> bool,
) -> Reduction<P::Cmd>
where P: Protocol, P::Cmd: Clone, P::Msg: Clone + PartialEq, P::Ind: Clone, P::Meta: Clone, P::Entry: Clone,
Expand description

Search for a smaller scenario whose run still satisfies predicate.

build is handed the candidate’s configuration and membership and returns a simulator over them, exactly as for Sim::run_scenario — it is called once per candidate, so it must be able to construct a fresh run each time. predicate is evaluated on the finished run.

predicate_name is carried into the report. Name the property, not the symptom.

§Panics

If the original scenario does not satisfy the predicate. There is then nothing to reduce, and returning something would mean returning a scenario that does not fail — which is the one outcome worse than returning the original.

The predicate itself must be total: return false for a run that does not exhibit what you are hunting, and do not assert. A predicate that panics makes the search unable to reject a candidate.