mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-18 00:54:19 +01:00
remove Span, as interaction ID is enough to determine membership of a property
This commit is contained in:
@@ -19,7 +19,7 @@ use crate::{
|
|||||||
Query,
|
Query,
|
||||||
interactions::{
|
interactions::{
|
||||||
Fault, Interaction, InteractionBuilder, InteractionPlan, InteractionPlanIterator,
|
Fault, Interaction, InteractionBuilder, InteractionPlan, InteractionPlanIterator,
|
||||||
InteractionType, Interactions, InteractionsType, Span,
|
InteractionType, Interactions, InteractionsType,
|
||||||
},
|
},
|
||||||
metrics::{InteractionStats, Remaining},
|
metrics::{InteractionStats, Remaining},
|
||||||
property::Property,
|
property::Property,
|
||||||
@@ -245,7 +245,6 @@ impl<'a, R: rand::Rng> InteractionPlanIterator for PlanGenerator<'a, R> {
|
|||||||
)
|
)
|
||||||
.connection_index(conn_index)
|
.connection_index(conn_index)
|
||||||
.id(self.plan.next_property_id())
|
.id(self.plan.next_property_id())
|
||||||
.span(Span::StartEnd)
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@@ -287,20 +286,14 @@ impl Interactions {
|
|||||||
InteractionsType::Query(query) => {
|
InteractionsType::Query(query) => {
|
||||||
let mut builder =
|
let mut builder =
|
||||||
InteractionBuilder::with_interaction(InteractionType::Query(query.clone()));
|
InteractionBuilder::with_interaction(InteractionType::Query(query.clone()));
|
||||||
builder
|
builder.connection_index(self.connection_index).id(id);
|
||||||
.connection_index(self.connection_index)
|
|
||||||
.id(id)
|
|
||||||
.span(Span::StartEnd);
|
|
||||||
let interaction = builder.build().unwrap();
|
let interaction = builder.build().unwrap();
|
||||||
vec![interaction]
|
vec![interaction]
|
||||||
}
|
}
|
||||||
InteractionsType::Fault(fault) => {
|
InteractionsType::Fault(fault) => {
|
||||||
let mut builder =
|
let mut builder =
|
||||||
InteractionBuilder::with_interaction(InteractionType::Fault(*fault));
|
InteractionBuilder::with_interaction(InteractionType::Fault(*fault));
|
||||||
builder
|
builder.connection_index(self.connection_index).id(id);
|
||||||
.connection_index(self.connection_index)
|
|
||||||
.id(id)
|
|
||||||
.span(Span::StartEnd);
|
|
||||||
let interaction = builder.build().unwrap();
|
let interaction = builder.build().unwrap();
|
||||||
vec![interaction]
|
vec![interaction]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ use crate::{
|
|||||||
model::{
|
model::{
|
||||||
Query, QueryCapabilities, QueryDiscriminants, ResultSet,
|
Query, QueryCapabilities, QueryDiscriminants, ResultSet,
|
||||||
interactions::{
|
interactions::{
|
||||||
Assertion, Interaction, InteractionBuilder, InteractionType, PropertyMetadata, Span,
|
Assertion, Interaction, InteractionBuilder, InteractionType, PropertyMetadata,
|
||||||
},
|
},
|
||||||
metrics::Remaining,
|
metrics::Remaining,
|
||||||
property::{InteractiveQueryInfo, Property, PropertyDiscriminants},
|
property::{InteractiveQueryInfo, Property, PropertyDiscriminants},
|
||||||
@@ -252,7 +252,7 @@ impl Property {
|
|||||||
connection_index: usize,
|
connection_index: usize,
|
||||||
id: NonZeroUsize,
|
id: NonZeroUsize,
|
||||||
) -> Vec<Interaction> {
|
) -> Vec<Interaction> {
|
||||||
let mut interactions: Vec<InteractionBuilder> = match self {
|
let interactions: Vec<InteractionBuilder> = match self {
|
||||||
Property::AllTableHaveExpectedContent { tables } => {
|
Property::AllTableHaveExpectedContent { tables } => {
|
||||||
assert_all_table_values(tables, connection_index).collect()
|
assert_all_table_values(tables, connection_index).collect()
|
||||||
}
|
}
|
||||||
@@ -1109,14 +1109,6 @@ impl Property {
|
|||||||
|
|
||||||
assert!(!interactions.is_empty());
|
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
|
interactions
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|mut builder| {
|
.map(|mut builder| {
|
||||||
|
|||||||
@@ -350,12 +350,17 @@ impl Display for InteractionPlan {
|
|||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
const PAD: usize = 4;
|
const PAD: usize = 4;
|
||||||
let mut indentation_level: usize = 0;
|
let mut indentation_level: usize = 0;
|
||||||
for interaction in &self.plan {
|
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())
|
if let Some(name) = interaction.property_meta.map(|p| p.property.name())
|
||||||
&& interaction.span.is_some_and(|span| span.start())
|
&& start
|
||||||
{
|
{
|
||||||
indentation_level = indentation_level.saturating_add(1);
|
indentation_level = indentation_level.saturating_add(1);
|
||||||
writeln!(f, "-- begin testing '{name}'")?;
|
writeln!(f, "-- begin testing '{name}'")?;
|
||||||
|
start = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if indentation_level > 0 {
|
if indentation_level > 0 {
|
||||||
@@ -364,12 +369,13 @@ impl Display for InteractionPlan {
|
|||||||
}
|
}
|
||||||
writeln!(f, "{interaction}")?;
|
writeln!(f, "{interaction}")?;
|
||||||
if let Some(name) = interaction.property_meta.map(|p| p.property.name())
|
if let Some(name) = interaction.property_meta.map(|p| p.property.name())
|
||||||
&& interaction.span.is_some_and(|span| span.end())
|
&& property.peek().is_none()
|
||||||
{
|
{
|
||||||
indentation_level = indentation_level.saturating_sub(1);
|
indentation_level = indentation_level.saturating_sub(1);
|
||||||
writeln!(f, "-- end testing '{name}'")?;
|
writeln!(f, "-- end testing '{name}'")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -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)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct PropertyMetadata {
|
pub struct PropertyMetadata {
|
||||||
pub property: PropertyDiscriminants,
|
pub property: PropertyDiscriminants,
|
||||||
@@ -466,7 +454,6 @@ impl PropertyMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, derive_builder::Builder)]
|
#[derive(Debug, Clone, derive_builder::Builder)]
|
||||||
#[builder(build_fn(validate = "Self::validate"))]
|
|
||||||
pub struct Interaction {
|
pub struct Interaction {
|
||||||
pub connection_index: usize,
|
pub connection_index: usize,
|
||||||
pub interaction: InteractionType,
|
pub interaction: InteractionType,
|
||||||
@@ -474,8 +461,6 @@ pub struct Interaction {
|
|||||||
pub ignore_error: bool,
|
pub ignore_error: bool,
|
||||||
#[builder(setter(strip_option), default)]
|
#[builder(setter(strip_option), default)]
|
||||||
pub property_meta: Option<PropertyMetadata>,
|
pub property_meta: Option<PropertyMetadata>,
|
||||||
#[builder(setter(strip_option), default)]
|
|
||||||
pub span: Option<Span>,
|
|
||||||
/// 0 id means the ID was not set
|
/// 0 id means the ID was not set
|
||||||
id: NonZeroUsize,
|
id: NonZeroUsize,
|
||||||
}
|
}
|
||||||
@@ -491,9 +476,6 @@ impl InteractionBuilder {
|
|||||||
if let Some(property_meta) = interaction.property_meta {
|
if let Some(property_meta) = interaction.property_meta {
|
||||||
builder.property_meta(property_meta);
|
builder.property_meta(property_meta);
|
||||||
}
|
}
|
||||||
if let Some(span) = interaction.span {
|
|
||||||
builder.span(span);
|
|
||||||
}
|
|
||||||
builder
|
builder
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -507,19 +489,6 @@ impl InteractionBuilder {
|
|||||||
pub fn has_property_meta(&self) -> bool {
|
pub fn has_property_meta(&self) -> bool {
|
||||||
self.property_meta.is_some()
|
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 {
|
impl Deref for Interaction {
|
||||||
|
|||||||
Reference in New Issue
Block a user