mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-07 02:04:21 +01:00
remove PanicGenerationContext and instead just pass the connection context directly
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
use sql_generation::generation::GenerationContext;
|
||||
|
||||
use crate::runner::env::ShadowTablesMut;
|
||||
|
||||
pub mod plan;
|
||||
@@ -19,17 +17,3 @@ pub(crate) trait Shadow {
|
||||
type Result;
|
||||
fn shadow(&self, tables: &mut ShadowTablesMut<'_>) -> Self::Result;
|
||||
}
|
||||
|
||||
/// Generation context that will always panic when called
|
||||
/// This is meant to be used when want to ensure that no downstream arbitrary fn will use this context
|
||||
pub struct PanicGenerationContext;
|
||||
|
||||
impl GenerationContext for PanicGenerationContext {
|
||||
fn tables(&self) -> &Vec<sql_generation::model::table::Table> {
|
||||
unimplemented!("you are not supposed to use this context")
|
||||
}
|
||||
|
||||
fn opts(&self) -> &sql_generation::generation::Opts {
|
||||
unimplemented!("you are not supposed to use this context")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ use turso_core::{Connection, Result, StepResult};
|
||||
|
||||
use crate::{
|
||||
SimulatorEnv,
|
||||
generation::{PanicGenerationContext, Shadow},
|
||||
generation::Shadow,
|
||||
model::Query,
|
||||
runner::env::{ShadowTablesMut, SimConnection, SimulationType},
|
||||
};
|
||||
@@ -226,8 +226,12 @@ impl InteractionPlan {
|
||||
|
||||
while plan.len() < num_interactions {
|
||||
tracing::debug!("Generating interaction {}/{}", plan.len(), num_interactions);
|
||||
let interactions =
|
||||
Interactions::arbitrary_from(rng, &PanicGenerationContext, (env, plan.stats()));
|
||||
let interactions = {
|
||||
let conn_index = env.choose_conn(rng);
|
||||
let conn_ctx = &env.connection_context(conn_index);
|
||||
Interactions::arbitrary_from(rng, conn_ctx, (env, plan.stats(), conn_index))
|
||||
};
|
||||
|
||||
interactions.shadow(&mut env.get_conn_tables_mut(interactions.connection_index));
|
||||
plan.push(interactions);
|
||||
}
|
||||
@@ -1000,11 +1004,11 @@ fn random_fault<R: rand::Rng>(rng: &mut R, env: &SimulatorEnv) -> Interactions {
|
||||
Interactions::new(env.choose_conn(rng), InteractionsType::Fault(fault))
|
||||
}
|
||||
|
||||
impl ArbitraryFrom<(&SimulatorEnv, InteractionStats)> for Interactions {
|
||||
impl ArbitraryFrom<(&SimulatorEnv, InteractionStats, usize)> for Interactions {
|
||||
fn arbitrary_from<R: rand::Rng, C: GenerationContext>(
|
||||
rng: &mut R,
|
||||
_context: &C,
|
||||
(env, stats): (&SimulatorEnv, InteractionStats),
|
||||
conn_ctx: &C,
|
||||
(env, stats, conn_index): (&SimulatorEnv, InteractionStats, usize),
|
||||
) -> Self {
|
||||
let remaining_ = remaining(
|
||||
env.opts.max_interactions,
|
||||
@@ -1012,7 +1016,6 @@ impl ArbitraryFrom<(&SimulatorEnv, InteractionStats)> for Interactions {
|
||||
&stats,
|
||||
env.profile.experimental_mvcc,
|
||||
);
|
||||
let conn_index = env.choose_conn(rng);
|
||||
frequency(
|
||||
vec![
|
||||
(
|
||||
@@ -1022,8 +1025,8 @@ impl ArbitraryFrom<(&SimulatorEnv, InteractionStats)> for Interactions {
|
||||
conn_index,
|
||||
InteractionsType::Property(Property::arbitrary_from(
|
||||
rng,
|
||||
&PanicGenerationContext,
|
||||
(env, &stats, conn_index),
|
||||
conn_ctx,
|
||||
(env, &stats),
|
||||
)),
|
||||
)
|
||||
}),
|
||||
|
||||
@@ -1514,13 +1514,12 @@ fn property_faulty_query<R: rand::Rng>(
|
||||
}
|
||||
}
|
||||
|
||||
impl ArbitraryFrom<(&SimulatorEnv, &InteractionStats, usize)> for Property {
|
||||
impl ArbitraryFrom<(&SimulatorEnv, &InteractionStats)> for Property {
|
||||
fn arbitrary_from<R: rand::Rng, C: GenerationContext>(
|
||||
rng: &mut R,
|
||||
_context: &C,
|
||||
(env, stats, conn_index): (&SimulatorEnv, &InteractionStats, usize),
|
||||
conn_ctx: &C,
|
||||
(env, stats): (&SimulatorEnv, &InteractionStats),
|
||||
) -> Self {
|
||||
let conn_ctx = &env.connection_context(conn_index);
|
||||
let opts = conn_ctx.opts();
|
||||
let remaining_ = remaining(
|
||||
env.opts.max_interactions,
|
||||
|
||||
Reference in New Issue
Block a user