summaryrefslogtreecommitdiff
path: root/tests/common
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2020-06-11 01:24:35 -0400
committerDeterminant <[email protected]>2020-06-11 01:24:35 -0400
commit9519f03cb2e9dc2642e95944b452c02f87fb3111 (patch)
treede63827b85f549dd227e78e3e03d0c86b8cf4700 /tests/common
parentc7d621279743275a8766fa253268fb7a8e1c90ca (diff)
scan through the single-point failure space
Diffstat (limited to 'tests/common')
-rw-r--r--tests/common/mod.rs27
1 files changed, 21 insertions, 6 deletions
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 43b717a..a5a41d5 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -99,11 +99,11 @@ where
}
impl<'a, G: FailGen, F: FnMut(WALBytes, WALRingId)> WALStoreEmul<'a, G, F> {
- pub fn new(state: &'a mut WALStoreEmulState, fail_gen: G,
+ pub fn new(state: &'a mut WALStoreEmulState, fgen: Rc<G>,
recover: F) -> Self {
WALStoreEmul {
state,
- fgen: Rc::new(fail_gen),
+ fgen,
recover
}
}
@@ -133,7 +133,7 @@ where
}
fn remove_file(&mut self, filename: &str) -> Result<(), ()> {
- println!("remove_file(filename={})", filename);
+ //println!("remove_file(filename={})", filename);
if self.fgen.next_fail() { return Err(()) }
self.state.files.remove(filename).ok_or(()).and_then(|_| Ok(()))
}
@@ -149,9 +149,9 @@ where
fn apply_payload(&mut self, payload: WALBytes, ringid: WALRingId) -> Result<(), ()> {
if self.fgen.next_fail() { return Err(()) }
- println!("apply_payload(payload=0x{}, ringid={:?})",
- hex::encode(&payload),
- ringid);
+ //println!("apply_payload(payload=0x{}, ringid={:?})",
+ // hex::encode(&payload),
+ // ringid);
(self.recover)(payload, ringid);
Ok(())
}
@@ -185,11 +185,26 @@ impl FailGen for ZeroFailGen {
fn next_fail(&self) -> bool { false }
}
+pub struct CountFailGen(std::cell::Cell<usize>);
+
+impl CountFailGen {
+ pub fn new() -> Self { CountFailGen(std::cell::Cell::new(0)) }
+ pub fn get_count(&self) -> usize { self.0.get() }
+}
+
+impl FailGen for CountFailGen {
+ fn next_fail(&self) -> bool {
+ self.0.set(self.0.get() + 1);
+ false
+ }
+}
+
/// An ordered list of intervals: `(begin, end, color)*`.
pub struct PaintStrokes(Vec<(u32, u32, u32)>);
impl PaintStrokes {
pub fn new() -> Self { PaintStrokes(Vec::new()) }
+ pub fn clone(&self) -> Self { PaintStrokes(self.0.clone()) }
pub fn to_bytes(&self) -> WALBytes {
let mut res: Vec<u8> = Vec::new();
let is = std::mem::size_of::<u32>();