aboutsummaryrefslogtreecommitdiff
path: root/tests/rand_fail.rs
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2020-06-10 22:35:21 -0400
committerDeterminant <[email protected]>2020-06-10 22:35:21 -0400
commit557392fe0672bc6b83ef2e0fec2c8ff7a6f22a54 (patch)
tree63ff6751fb2ef4b44a9e1949cca9df329d7fb9b8 /tests/rand_fail.rs
parent5b3cadb74fa4de64cf1006808167d36dfbc45a8d (diff)
fix bugs in dealing with long WAL rings
Diffstat (limited to 'tests/rand_fail.rs')
-rw-r--r--tests/rand_fail.rs65
1 files changed, 50 insertions, 15 deletions
diff --git a/tests/rand_fail.rs b/tests/rand_fail.rs
index b4e30ac..0cd519c 100644
--- a/tests/rand_fail.rs
+++ b/tests/rand_fail.rs
@@ -1,26 +1,61 @@
#[cfg(test)]
-extern crate growthring;
-use growthring::wal::{WALLoader, WALWriter, WALStore, WALRingId, WALBytes};
-
mod common;
+use growthring::wal::{WALLoader, WALWriter, WALStore, WALRingId, WALBytes, WALPos};
+use common::{FailGen, SingleFailGen, Canvas, WALStoreEmulState, WALStoreEmul, PaintStrokes};
-fn test<S: WALStore>(records: Vec<String>, wal: &mut WALWriter<S>) -> Box<[WALRingId]> {
- let records: Vec<WALBytes> = records.into_iter().map(|s| s.into_bytes().into_boxed_slice()).collect();
- let ret = wal.grow(&records).unwrap();
- for ring_id in ret.iter() {
- println!("got ring id: {:?}", ring_id);
+fn run<F: WALStore, R: rand::Rng>(n: usize, m: usize, k: usize,
+ canvas: &mut Canvas, wal: &mut WALWriter<F>, trace: &mut Vec<u32>,
+ rng: &mut R) -> Result<(), ()> {
+ for i in 0..n {
+ let s = (0..m).map(|_|
+ PaintStrokes::gen_rand(1000, 10, 256, 5, rng)).collect::<Vec<PaintStrokes>>();
+ let recs = s.iter().map(|e| e.to_bytes()).collect::<Vec<WALBytes>>();
+ // write ahead
+ let rids = wal.grow(recs)?;
+ for rid in rids.iter() {
+ println!("got ring id: {:?}", rid);
+ }
+ // WAL append done
+ // prepare data writes
+ for (e, rid) in s.iter().zip(rids.iter()) {
+ canvas.prepaint(e, &*rid)
+ }
+ // run the scheduler for a bit
+ for _ in 0..k {
+ if let Some((fin_rid, t)) = canvas.rand_paint(rng) {
+ if let Some(rid) = fin_rid {
+ wal.peel(&[rid])?
+ }
+ trace.push(t);
+ } else { break }
+ }
+ }
+ while let Some((fin_rid, t)) = canvas.rand_paint(rng) {
+ if let Some(rid) = fin_rid {
+ wal.peel(&[rid])?
+ }
+ trace.push(t);
}
- ret
+ canvas.print(40);
+ Ok(())
+}
+
+fn check<F: WALStore>(canvas: &mut Canvas, wal: &mut WALLoader<F>, trace: &Vec<u8>) -> bool {
+ true
}
#[test]
fn test_rand_fail() {
- let fgen = common::SingleFailGen::new(100);
- let mut state = common::WALStoreEmulState::new();
- let mut wal = WALLoader::new(common::WALStoreEmul::new(&mut state, fgen), 9, 8, 1000).recover().unwrap();
- for _ in 0..3 {
- test(["hi", "hello", "lol"].iter().map(|s| s.to_string()).collect::<Vec<String>>(), &mut wal);
- }
+ let fgen = SingleFailGen::new(100000);
+ 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 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();
}