diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 8e3609fd5..5ea79cb46 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -4811,7 +4811,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", - "libm", ] [[package]] @@ -5758,7 +5757,7 @@ checksum = "43d84d1d7a6ac92673717f9f6d1518374ef257669c24ebc5ac25d5033828be58" [[package]] name = "proptest" version = "1.5.0" -source = "git+https://github.com/proptest-rs/proptest?branch=master#f8a84d5c2ecb3577d447e8340fd05e238a330007" +source = "git+https://github.com/proptest-rs/proptest?branch=main#772e64733187dc65f669db51f627ddf9e8951bc8" dependencies = [ "bit-set 0.8.0", "bit-vec 0.8.0", @@ -5777,7 +5776,7 @@ dependencies = [ [[package]] name = "proptest-state-machine" version = "0.3.0" -source = "git+https://github.com/proptest-rs/proptest?branch=master#f8a84d5c2ecb3577d447e8340fd05e238a330007" +source = "git+https://github.com/proptest-rs/proptest?branch=main#772e64733187dc65f669db51f627ddf9e8951bc8" dependencies = [ "proptest", ] diff --git a/rust/Cargo.toml b/rust/Cargo.toml index f2ff941e5..a8d205519 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -78,8 +78,8 @@ boringtun = { git = "https://github.com/cloudflare/boringtun", branch = "master" str0m = { git = "https://github.com/algesten/str0m", branch = "main" } ip_network = { git = "https://github.com/JakubOnderka/ip_network", branch = "master" } # Waiting for release. ip_network_table = { git = "https://github.com/edmonds/ip_network_table", branch = "some-useful-traits" } # For `Debug` and `Clone` -proptest = { git = "https://github.com/proptest-rs/proptest", branch = "master" } -proptest-state-machine = { git = "https://github.com/proptest-rs/proptest", branch = "master" } +proptest = { git = "https://github.com/proptest-rs/proptest", branch = "main" } +proptest-state-machine = { git = "https://github.com/proptest-rs/proptest", branch = "main" } tracing-stackdriver = { git = "https://github.com/thomaseizinger/tracing-stackdriver", branch = "deps/bump-otel-0.23" } # Waiting for release. # Enforce `tracing-macros` to have released `tracing` version. diff --git a/rust/connlib/tunnel/src/tests.rs b/rust/connlib/tunnel/src/tests.rs index 2cd2b248e..c2335f203 100644 --- a/rust/connlib/tunnel/src/tests.rs +++ b/rust/connlib/tunnel/src/tests.rs @@ -2,10 +2,11 @@ use crate::tests::{flux_capacitor::FluxCapacitor, sut::TunnelTest}; use assertions::PanicOnErrorEvents; use core::fmt; use proptest::{ + sample::SizeRange, strategy::{Strategy, ValueTree as _}, test_runner::{Config, RngAlgorithm, TestError, TestRng, TestRunner}, }; -use proptest_state_machine::ReferenceStateMachine; +use proptest_state_machine::Sequential; use reference::ReferenceState; use std::sync::atomic::{self, AtomicU32}; use tracing_subscriber::{ @@ -45,8 +46,16 @@ fn tunnel_test() { let _ = std::fs::create_dir_all("testcases"); let test_runner = &mut TestRunner::new(config); + let strategy = Sequential::new( + SizeRange::new(5..=15), + ReferenceState::initial_state, + ReferenceState::is_valid_transition, + ReferenceState::transitions, + ReferenceState::apply, + ); + let result = test_runner.run( - &ReferenceState::sequential_strategy(5..15), + &strategy, |(mut ref_state, transitions, mut seen_counter)| { let test_index = test_index.fetch_add(1, std::sync::atomic::Ordering::Relaxed); let flux_capacitor = FluxCapacitor::default(); @@ -120,8 +129,8 @@ fn tunnel_test() { #[test] fn reference_state_is_deterministic() { for n in 0..1000 { - let state1 = sample_from_strategy(n, ReferenceState::init_state()); - let state2 = sample_from_strategy(n, ReferenceState::init_state()); + let state1 = sample_from_strategy(n, ReferenceState::initial_state()); + let state2 = sample_from_strategy(n, ReferenceState::initial_state()); assert_eq!(format!("{state1:?}"), format!("{state2:?}")); } @@ -130,7 +139,7 @@ fn reference_state_is_deterministic() { #[test] fn transitions_are_deterministic() { for n in 0..1000 { - let state = sample_from_strategy(n, ReferenceState::init_state()); + let state = sample_from_strategy(n, ReferenceState::initial_state()); let transitions1 = sample_from_strategy(n, ReferenceState::transitions(&state)); let transitions2 = sample_from_strategy(n, ReferenceState::transitions(&state)); diff --git a/rust/connlib/tunnel/src/tests/reference.rs b/rust/connlib/tunnel/src/tests/reference.rs index 026017151..87f3ba077 100644 --- a/rust/connlib/tunnel/src/tests/reference.rs +++ b/rust/connlib/tunnel/src/tests/reference.rs @@ -7,7 +7,6 @@ use crate::{dns::is_subdomain, proptest::relay_id}; use connlib_model::{GatewayId, RelayId, ResourceId, StaticSecret}; use domain::base::Rtype; use proptest::{prelude::*, sample}; -use proptest_state_machine::ReferenceStateMachine; use std::{ collections::{BTreeMap, BTreeSet, HashSet}, fmt, iter, @@ -49,11 +48,8 @@ pub(crate) enum ResourceDst { /// The logic in here represents what we expect the [`ClientState`] & [`GatewayState`] to do. /// Care has to be taken that we don't implement things in a buggy way here. /// After all, if your test has bugs, it won't catch any in the actual implementation. -impl ReferenceStateMachine for ReferenceState { - type State = Self; - type Transition = Transition; - - fn init_state() -> BoxedStrategy { +impl ReferenceState { + pub(crate) fn initial_state() -> BoxedStrategy { (stub_portal(), dns_servers()) .prop_flat_map(|(portal, dns_servers)| { let gateways = portal.gateways(); @@ -169,7 +165,7 @@ impl ReferenceStateMachine for ReferenceState { /// /// This is invoked by proptest repeatedly to explore further state transitions. /// Here, we should only generate [`Transition`]s that make sense for the current state. - fn transitions(state: &Self::State) -> BoxedStrategy { + pub(crate) fn transitions(state: &Self) -> BoxedStrategy { CompositeStrategy::default() .with( 1, @@ -286,7 +282,7 @@ impl ReferenceStateMachine for ReferenceState { /// Apply the transition to our reference state. /// /// Here is where we implement the "expected" logic. - fn apply(mut state: Self::State, transition: &Self::Transition) -> Self::State { + pub(crate) fn apply(mut state: Self, transition: &Transition) -> Self { match transition { Transition::ActivateResource(resource) => { state.client.exec_mut(|client| match resource { @@ -473,7 +469,7 @@ impl ReferenceStateMachine for ReferenceState { } /// Any additional checks on whether a particular [`Transition`] can be applied to a certain state. - fn preconditions(state: &Self::State, transition: &Self::Transition) -> bool { + pub(crate) fn is_valid_transition(state: &Self, transition: &Transition) -> bool { match transition { Transition::ActivateResource(resource) => { // Don't add resource we already have.