From f09b73c768e20be9fa1301489c32ebfa18edc025 Mon Sep 17 00:00:00 2001 From: pedrocarlo Date: Sat, 1 Nov 2025 14:13:47 -0300 Subject: [PATCH] remove Span, as interaction ID is enough to determine membership of a property --- simulator/generation/plan.rs | 13 ++---- simulator/generation/property.rs | 12 +---- simulator/model/interactions.rs | 77 ++++++++++---------------------- 3 files changed, 28 insertions(+), 74 deletions(-) diff --git a/simulator/generation/plan.rs b/simulator/generation/plan.rs index a02b673dc..f4a265b61 100644 --- a/simulator/generation/plan.rs +++ b/simulator/generation/plan.rs @@ -19,7 +19,7 @@ use crate::{ Query, interactions::{ Fault, Interaction, InteractionBuilder, InteractionPlan, InteractionPlanIterator, - InteractionType, Interactions, InteractionsType, Span, + InteractionType, Interactions, InteractionsType, }, metrics::{InteractionStats, Remaining}, property::Property, @@ -245,7 +245,6 @@ impl<'a, R: rand::Rng> InteractionPlanIterator for PlanGenerator<'a, R> { ) .connection_index(conn_index) .id(self.plan.next_property_id()) - .span(Span::StartEnd) .build() .unwrap(); @@ -287,20 +286,14 @@ impl Interactions { InteractionsType::Query(query) => { let mut builder = InteractionBuilder::with_interaction(InteractionType::Query(query.clone())); - builder - .connection_index(self.connection_index) - .id(id) - .span(Span::StartEnd); + builder.connection_index(self.connection_index).id(id); let interaction = builder.build().unwrap(); vec![interaction] } InteractionsType::Fault(fault) => { let mut builder = InteractionBuilder::with_interaction(InteractionType::Fault(*fault)); - builder - .connection_index(self.connection_index) - .id(id) - .span(Span::StartEnd); + builder.connection_index(self.connection_index).id(id); let interaction = builder.build().unwrap(); vec![interaction] } diff --git a/simulator/generation/property.rs b/simulator/generation/property.rs index 7c8ba06d9..070676f0d 100644 --- a/simulator/generation/property.rs +++ b/simulator/generation/property.rs @@ -32,7 +32,7 @@ use crate::{ model::{ Query, QueryCapabilities, QueryDiscriminants, ResultSet, interactions::{ - Assertion, Interaction, InteractionBuilder, InteractionType, PropertyMetadata, Span, + Assertion, Interaction, InteractionBuilder, InteractionType, PropertyMetadata, }, metrics::Remaining, property::{InteractiveQueryInfo, Property, PropertyDiscriminants}, @@ -252,7 +252,7 @@ impl Property { connection_index: usize, id: NonZeroUsize, ) -> Vec { - let mut interactions: Vec = match self { + let interactions: Vec = match self { Property::AllTableHaveExpectedContent { tables } => { assert_all_table_values(tables, connection_index).collect() } @@ -1109,14 +1109,6 @@ impl Property { assert!(!interactions.is_empty()); - // Add a span to the interactions that matter - if interactions.len() == 1 { - interactions.first_mut().unwrap().span(Span::StartEnd); - } else { - interactions.first_mut().unwrap().span(Span::Start); - interactions.last_mut().unwrap().span(Span::End); - }; - interactions .into_iter() .map(|mut builder| { diff --git a/simulator/model/interactions.rs b/simulator/model/interactions.rs index 4c389daf4..e69887604 100644 --- a/simulator/model/interactions.rs +++ b/simulator/model/interactions.rs @@ -350,24 +350,30 @@ impl Display for InteractionPlan { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { const PAD: usize = 4; let mut indentation_level: usize = 0; - for interaction in &self.plan { - if let Some(name) = interaction.property_meta.map(|p| p.property.name()) - && interaction.span.is_some_and(|span| span.start()) - { - indentation_level = indentation_level.saturating_add(1); - writeln!(f, "-- begin testing '{name}'")?; - } + let mut iter = self.iter_properties(); + while let Some(property) = iter.next_property() { + let mut property = property.peekable(); + let mut start = true; + while let Some((_, interaction)) = property.next() { + if let Some(name) = interaction.property_meta.map(|p| p.property.name()) + && start + { + indentation_level = indentation_level.saturating_add(1); + writeln!(f, "-- begin testing '{name}'")?; + start = false; + } - if indentation_level > 0 { - let padding = " ".repeat(indentation_level * PAD); - f.pad(&padding)?; - } - writeln!(f, "{interaction}")?; - if let Some(name) = interaction.property_meta.map(|p| p.property.name()) - && interaction.span.is_some_and(|span| span.end()) - { - indentation_level = indentation_level.saturating_sub(1); - writeln!(f, "-- end testing '{name}'")?; + if indentation_level > 0 { + let padding = " ".repeat(indentation_level * PAD); + f.pad(&padding)?; + } + writeln!(f, "{interaction}")?; + if let Some(name) = interaction.property_meta.map(|p| p.property.name()) + && property.peek().is_none() + { + indentation_level = indentation_level.saturating_sub(1); + writeln!(f, "-- end testing '{name}'")?; + } } } @@ -431,24 +437,6 @@ impl Display for Fault { } } -#[derive(Debug, Clone, Copy)] -pub enum Span { - Start, - End, - // Both start and end - StartEnd, -} - -impl Span { - fn start(&self) -> bool { - matches!(self, Self::Start | Self::StartEnd) - } - - fn end(&self) -> bool { - matches!(self, Self::End | Self::StartEnd) - } -} - #[derive(Debug, Clone, Copy)] pub struct PropertyMetadata { pub property: PropertyDiscriminants, @@ -466,7 +454,6 @@ impl PropertyMetadata { } #[derive(Debug, Clone, derive_builder::Builder)] -#[builder(build_fn(validate = "Self::validate"))] pub struct Interaction { pub connection_index: usize, pub interaction: InteractionType, @@ -474,8 +461,6 @@ pub struct Interaction { pub ignore_error: bool, #[builder(setter(strip_option), default)] pub property_meta: Option, - #[builder(setter(strip_option), default)] - pub span: Option, /// 0 id means the ID was not set id: NonZeroUsize, } @@ -491,9 +476,6 @@ impl InteractionBuilder { if let Some(property_meta) = interaction.property_meta { builder.property_meta(property_meta); } - if let Some(span) = interaction.span { - builder.span(span); - } builder } @@ -507,19 +489,6 @@ impl InteractionBuilder { pub fn has_property_meta(&self) -> bool { self.property_meta.is_some() } - - fn validate(&self) -> Result<(), InteractionBuilderError> { - // Cannot have span and property_meta.extension being true at the same time - if let Some(property_meta) = self.property_meta.flatten() - && property_meta.extension - && self.span.flatten().is_some() - { - return Err(InteractionBuilderError::ValidationError( - "cannot have a span set with an extension query".to_string(), - )); - } - Ok(()) - } } impl Deref for Interaction {