mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-04 08:54:20 +01:00
Merge 'simulator: fix shrinking bug' from Alperen Keleş
Fixes https://github.com/tursodatabase/limbo/issues/924 Closes #935
This commit is contained in:
@@ -47,9 +47,9 @@ impl InteractionPlan {
|
||||
.map(|i| i.interactions())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let (mut i, mut j1, mut j2) = (0, 0, 0);
|
||||
let (mut i, mut j) = (0, 0);
|
||||
|
||||
while i < interactions.len() && j1 < plan.len() {
|
||||
while i < interactions.len() && j < plan.len() {
|
||||
if interactions[i].starts_with("-- begin")
|
||||
|| interactions[i].starts_with("-- end")
|
||||
|| interactions[i].is_empty()
|
||||
@@ -58,28 +58,30 @@ impl InteractionPlan {
|
||||
continue;
|
||||
}
|
||||
|
||||
if interactions[i].contains(plan[j1][j2].to_string().as_str()) {
|
||||
i += 1;
|
||||
if j2 + 1 < plan[j1].len() {
|
||||
j2 += 1;
|
||||
} else {
|
||||
j1 += 1;
|
||||
j2 = 0;
|
||||
}
|
||||
} else {
|
||||
plan[j1].remove(j2);
|
||||
// interactions[i] is the i'th line in the human readable plan
|
||||
// plan[j][k] is the k'th interaction in the j'th property
|
||||
let mut k = 0;
|
||||
|
||||
if plan[j1].is_empty() {
|
||||
plan.remove(j1);
|
||||
j2 = 0;
|
||||
while k < plan[j].len() {
|
||||
if i >= interactions.len() {
|
||||
let _ = plan.split_off(j + 1);
|
||||
let _ = plan[j].split_off(k);
|
||||
break;
|
||||
}
|
||||
|
||||
if interactions[i].contains(plan[j][k].to_string().as_str()) {
|
||||
i += 1;
|
||||
k += 1;
|
||||
} else {
|
||||
plan[j].remove(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
if j1 < plan.len() {
|
||||
if j2 < plan[j1].len() {
|
||||
let _ = plan[j1].split_off(j2);
|
||||
|
||||
if plan[j].is_empty() {
|
||||
plan.remove(j);
|
||||
} else {
|
||||
j += 1;
|
||||
}
|
||||
let _ = plan.split_off(j1);
|
||||
}
|
||||
|
||||
plan
|
||||
|
||||
@@ -233,6 +233,10 @@ fn run_simulator(
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Write the shrunk plan to a file
|
||||
let mut f = std::fs::File::create(&paths.shrunk_plan).unwrap();
|
||||
f.write_all(shrunk_plans[0].to_string().as_bytes()).unwrap();
|
||||
|
||||
let last_execution = Arc::new(Mutex::new(*last_execution));
|
||||
|
||||
let shrunk = SandboxedResult::from(
|
||||
@@ -270,11 +274,6 @@ fn run_simulator(
|
||||
log::error!("shrinking failed, the error was not properly reproduced");
|
||||
}
|
||||
}
|
||||
|
||||
// Write the shrunk plan to a file
|
||||
let shrunk_plan = std::fs::read(&paths.shrunk_plan).unwrap();
|
||||
let mut f = std::fs::File::create(&paths.shrunk_plan).unwrap();
|
||||
f.write_all(&shrunk_plan).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ pub(crate) fn execute_plans(
|
||||
) -> ExecutionResult {
|
||||
let mut history = ExecutionHistory::new();
|
||||
let now = std::time::Instant::now();
|
||||
env.clear_poison();
|
||||
let mut env = env.lock().unwrap();
|
||||
for _tick in 0..env.opts.ticks {
|
||||
// Pick the connection to interact with
|
||||
|
||||
Reference in New Issue
Block a user