Improve log tests
#![cfg_attr(test, allow(unused))]
-#[cfg(target_os = "linux")]
-extern crate libc;
-extern crate quickcheck;
-extern crate rand;
-
-extern crate pagecache;
-extern crate sled;
-extern crate tests;
-
-use std::fs;
-use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
-use std::sync::Arc;
-use std::thread;
-
-use quickcheck::{Arbitrary, Gen, QuickCheck, StdGen};
-use rand::{thread_rng, Rng};
-
-use pagecache::{
+use {
+ lazy_static::lazy_static,
+ pagecache::{
ConfigBuilder, DiskPtr, Log, LogRead, SegmentMode,
MINIMUM_ITEMS_PER_SEGMENT, MSG_HEADER_LEN, SEG_HEADER_LEN,
SEG_TRAILER_LEN,
+ },
+ quickcheck::{Arbitrary, Gen, QuickCheck, StdGen},
+ rand::{thread_rng, Rng},
+ std::{
+ fs,
+ sync::{
+ atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT},
+ {Arc, Mutex},
+ },
+ thread,
+ },
};
type Lsn = i64;
@@ -454,6 +450,19 @@ impl Arbitrary for Op {
}
fn prop_log_works(ops: Vec<Op>, flusher: bool) -> bool {
+ tests::setup_logger();
+
+ /*
+ lazy_static! {
+ // forces quickcheck to run one thread at a time
+ static ref M: Mutex<()> = Mutex::new(());
+ }
+
+ let _lock =
+ M.lock().expect("our test lock should not be poisoned");
+ */
+
+ println!("ops: {:?}", ops);
use self::Op::*;
let config = ConfigBuilder::new()
.temporary(true)
@@ -507,6 +516,8 @@ fn prop_log_works(ops: Vec<Op>, flusher: bool) -> bool {
Restart => {
drop(log);
+ println!("\nrestarting\n");
+
// on recovery, we will rewind over any aborted tip entries
while !reference.is_empty() {
let should_pop =
@@ -853,6 +864,34 @@ fn log_bug_22() {
);
}
+#[test]
+fn log_bug_23() {
+ // postmortem:
+ use self::Op::*;
+ prop_log_works(vec![AbortReservation(vec![230]), Restart], false);
+}
+
+#[test]
+fn log_bug_24() {
+ // postmortem:
+ use self::Op::*;
+ prop_log_works(
+ vec![
+ AbortReservation(vec![107]),
+ Restart,
+ AbortReservation(vec![109]),
+ Write(vec![110]),
+ Write(vec![111]),
+ Write(vec![112]),
+ Restart,
+ AbortReservation(vec![]),
+ Write(vec![114]),
+ Read(1),
+ ],
+ false,
+ );
+}
+
fn _log_bug_() {
// postmortem: TEMPLATE
// use self::Op::*;
