mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-05 01:04:22 +01:00
Impl truncate for simulator
This commit is contained in:
@@ -225,6 +225,38 @@ impl File for SimulatorFile {
|
||||
fn size(&self) -> Result<u64> {
|
||||
self.inner.size()
|
||||
}
|
||||
|
||||
fn truncate(
|
||||
&self,
|
||||
len: usize,
|
||||
mut c: turso_core::Completion,
|
||||
) -> Result<Arc<turso_core::Completion>> {
|
||||
if self.fault.get() {
|
||||
return Err(turso_core::LimboError::InternalError(
|
||||
FAULT_ERROR_MSG.into(),
|
||||
));
|
||||
}
|
||||
if let Some(latency) = self.generate_latency_duration() {
|
||||
let CompletionType::Truncate(truncate_completion) = &mut c.completion_type else {
|
||||
unreachable!();
|
||||
};
|
||||
let before = self.rng.borrow_mut().gen_bool(0.5);
|
||||
let dummy_complete = Box::new(|_| {});
|
||||
let prev_complete =
|
||||
std::mem::replace(&mut truncate_completion.complete, dummy_complete);
|
||||
let new_complete = move |res| {
|
||||
if before {
|
||||
std::thread::sleep(latency);
|
||||
}
|
||||
(prev_complete)(res);
|
||||
if !before {
|
||||
std::thread::sleep(latency);
|
||||
}
|
||||
};
|
||||
truncate_completion.complete = Box::new(new_complete);
|
||||
};
|
||||
self.inner.truncate(len, c)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for SimulatorFile {
|
||||
|
||||
Reference in New Issue
Block a user