remove Span, as interaction ID is enough to determine membership of a property

This commit is contained in:
pedrocarlo
2025-11-01 14:13:47 -03:00
parent 2aab33b714
commit f09b73c768
3 changed files with 28 additions and 74 deletions

View File

@@ -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]
}

View File

@@ -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<Interaction> {
let mut interactions: Vec<InteractionBuilder> = match self {
let interactions: Vec<InteractionBuilder> = 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| {

View File

@@ -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<PropertyMetadata>,
#[builder(setter(strip_option), default)]
pub span: Option<Span>,
/// 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 {