mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-19 01:24:20 +01:00
fix non-determinism bug arising from a call to thread_rng while picking
which row to check existence for in the result of the select query
This commit is contained in:
@@ -7,7 +7,7 @@ use crate::{
|
||||
};
|
||||
|
||||
use super::{
|
||||
frequency, pick,
|
||||
frequency, pick, pick_index,
|
||||
plan::{Assertion, Interaction, InteractionStats, ResultSet},
|
||||
ArbitraryFrom,
|
||||
};
|
||||
@@ -34,6 +34,8 @@ pub(crate) enum Property {
|
||||
InsertSelect {
|
||||
/// The insert query
|
||||
insert: Insert,
|
||||
/// Selected row index
|
||||
row_index: usize,
|
||||
/// Additional interactions in the middle of the property
|
||||
queries: Vec<Query>,
|
||||
/// The select query
|
||||
@@ -73,6 +75,7 @@ impl Property {
|
||||
match self {
|
||||
Property::InsertSelect {
|
||||
insert,
|
||||
row_index,
|
||||
queries,
|
||||
select,
|
||||
} => {
|
||||
@@ -83,7 +86,7 @@ impl Property {
|
||||
);
|
||||
|
||||
// Pick a random row within the insert values
|
||||
let row = pick(&insert.values, &mut rand::thread_rng()).clone();
|
||||
let row = insert.values[*row_index].clone();
|
||||
|
||||
// Assume that the table exists
|
||||
let assumption = Interaction::Assumption(Assertion {
|
||||
@@ -202,7 +205,8 @@ fn property_insert_select<R: rand::Rng>(
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Pick a random row to select
|
||||
let row = pick(&rows, rng).clone();
|
||||
let row_index = pick_index(rows.len(), rng).clone();
|
||||
let row = rows[row_index].clone();
|
||||
|
||||
// Insert the rows
|
||||
let insert_query = Insert {
|
||||
@@ -248,6 +252,7 @@ fn property_insert_select<R: rand::Rng>(
|
||||
|
||||
Property::InsertSelect {
|
||||
insert: insert_query,
|
||||
row_index,
|
||||
queries,
|
||||
select: select_query,
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ fn main() -> Result<(), String> {
|
||||
last_execution,
|
||||
);
|
||||
|
||||
match (shrunk, &result) {
|
||||
match (&shrunk, &result) {
|
||||
(
|
||||
SandboxedResult::Panicked { error: e1, .. },
|
||||
SandboxedResult::Panicked { error: e2, .. },
|
||||
@@ -227,7 +227,7 @@ fn main() -> Result<(), String> {
|
||||
SandboxedResult::FoundBug { error: e1, .. },
|
||||
SandboxedResult::FoundBug { error: e2, .. },
|
||||
) => {
|
||||
if &e1 != e2 {
|
||||
if e1 != e2 {
|
||||
log::error!(
|
||||
"shrinking failed, the error was not properly reproduced"
|
||||
);
|
||||
@@ -291,6 +291,7 @@ fn revert_db_and_plan_files(output_dir: &Path) {
|
||||
std::fs::rename(&new_plan_path, &old_plan_path).unwrap();
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum SandboxedResult {
|
||||
Panicked {
|
||||
error: String,
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::generation::{
|
||||
|
||||
use super::env::{SimConnection, SimulatorEnv};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub(crate) struct Execution {
|
||||
pub(crate) connection_index: usize,
|
||||
pub(crate) interaction_index: usize,
|
||||
@@ -30,6 +30,7 @@ impl Execution {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct ExecutionHistory {
|
||||
pub(crate) history: Vec<Execution>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user