summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/common/mod.rs26
-rw-r--r--tests/rand_fail.rs11
2 files changed, 25 insertions, 12 deletions
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index ce27e16..a8dab51 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -89,18 +89,29 @@ impl WALStoreEmulState {
}
/// Emulate the persistent storage state.
-pub struct WALStoreEmul<'a, G: FailGen> {
+pub struct WALStoreEmul<'a, G, F>
+where
+ G: FailGen,
+ F: Fn(WALBytes, WALPos) {
state: &'a mut WALStoreEmulState,
- fgen: Rc<G>
+ fgen: Rc<G>,
+ recover: F
}
-impl<'a, G: FailGen> WALStoreEmul<'a, G> {
- pub fn new(state: &'a mut WALStoreEmulState, fail_gen: G) -> Self {
- WALStoreEmul { state, fgen: Rc::new(fail_gen) }
+impl<'a, G: FailGen, F: Fn(WALBytes, WALPos)> WALStoreEmul<'a, G, F> {
+ pub fn new(state: &'a mut WALStoreEmulState, fail_gen: G,
+ recover: F) -> Self {
+ WALStoreEmul {
+ state,
+ fgen: Rc::new(fail_gen),
+ recover
+ }
}
}
-impl<'a, G: 'static + FailGen> WALStore for WALStoreEmul<'a, G> {
+impl<'a, G, F> WALStore for WALStoreEmul<'a, G, F>
+where
+ G: 'static + FailGen, F: Fn(WALBytes, WALPos) {
type FileNameIter = std::vec::IntoIter<String>;
fn open_file(&mut self, filename: &str, touch: bool) -> Result<Box<dyn WALFile>, ()> {
@@ -122,7 +133,7 @@ impl<'a, G: 'static + FailGen> WALStore for WALStoreEmul<'a, G> {
}
fn remove_file(&mut self, filename: &str) -> Result<(), ()> {
- println!("remove {}", filename);
+ println!("remove_file(filename={})", filename);
if self.fgen.next_fail() { return Err(()) }
self.state.files.remove(filename).ok_or(()).and_then(|_| Ok(()))
}
@@ -141,6 +152,7 @@ impl<'a, G: 'static + FailGen> WALStore for WALStoreEmul<'a, G> {
println!("apply_payload(payload=0x{}, wal_off={})",
hex::encode(&payload),
wal_off);
+ (self.recover)(payload, wal_off);
Ok(())
}
}
diff --git a/tests/rand_fail.rs b/tests/rand_fail.rs
index 0cd519c..6c2c3c1 100644
--- a/tests/rand_fail.rs
+++ b/tests/rand_fail.rs
@@ -41,21 +41,22 @@ fn run<F: WALStore, R: rand::Rng>(n: usize, m: usize, k: usize,
Ok(())
}
-fn check<F: WALStore>(canvas: &mut Canvas, wal: &mut WALLoader<F>, trace: &Vec<u8>) -> bool {
+fn check<F: WALStore>(canvas: &mut Canvas, wal: &mut WALLoader<F>, trace: &Vec<u32>) -> bool {
true
}
#[test]
fn test_rand_fail() {
- let fgen = SingleFailGen::new(100000);
+ let fgen = SingleFailGen::new(100);
let n = 100;
let m = 10;
let k = 100;
let mut rng = rand::thread_rng();
let mut state = WALStoreEmulState::new();
- let mut wal = WALLoader::new(WALStoreEmul::new(&mut state, fgen), 9, 8, 1000).recover().unwrap();
+ let mut wal = WALLoader::new(WALStoreEmul::new(&mut state, fgen, |_, _|{}), 9, 8, 1000).recover().unwrap();
let mut trace: Vec<u32> = Vec::new();
let mut canvas = Canvas::new(1000);
- run(n, m, k, &mut canvas, &mut wal, &mut trace, &mut rng).unwrap();
- WALLoader::new(common::WALStoreEmul::new(&mut state, common::ZeroFailGen), 9, 8, 1000).recover().unwrap();
+ run(n, m, k, &mut canvas, &mut wal, &mut trace, &mut rng); //.unwrap();
+ let mut wal = WALLoader::new(WALStoreEmul::new(&mut state, common::ZeroFailGen, |payload, wal_off|{}), 9, 8, 1000);
+ assert!(check(&mut canvas, &mut wal, &trace));
}