Skip to content

Commit

Permalink
Suffix test log files with a timestamp
Browse files Browse the repository at this point in the history
This ensures that subsequent test runs always use new log files, even if
the previous test run caused a panic.
  • Loading branch information
ekmartin committed Nov 10, 2017
1 parent df8a1b8 commit 458f854
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/tests.rs
@@ -1,3 +1,4 @@
extern crate time;

use core::{DataType, Datas};
use dataflow::DomainBuilder;
Expand Down Expand Up @@ -27,7 +28,7 @@ use recipe::{ActivationResult, Recipe};
use sql::reuse::ReuseConfigType;
use sql::{SqlIncorporator, ToFlowParts};

use std::time;
use std::time::Duration;
use std::thread;
use std::sync::mpsc;
use std::env;
Expand All @@ -36,13 +37,20 @@ use std::collections::HashMap;

const DEFAULT_SETTLE_TIME_MS: u64 = 100;

fn get_settle_time() -> time::Duration {
fn get_settle_time() -> Duration {
let settle_time: u64 = match env::var("SETTLE_TIME") {
Ok(value) => value.parse().unwrap(),
Err(_) => DEFAULT_SETTLE_TIME_MS,
};

time::Duration::from_millis(settle_time)
Duration::from_millis(settle_time)
}

// Suffixes the given log base with a timestamp, ensuring that
// subsequent test runs do not reuse log files in the case of failures:
fn get_log_name(base: &str) -> String {
let current_time = time::get_time();
format!("{}-{}-{}", base, current_time.sec, current_time.nsec)
}

// Sleeps for either DEFAULT_SETTLE_TIME_MS milliseconds, or
Expand All @@ -58,8 +66,8 @@ fn it_works_basic() {
let pparams = PersistenceParameters::new(
DurabilityMode::DeleteOnExit,
128,
time::Duration::from_millis(1),
Some(String::from("it_works_basic")),
Duration::from_millis(1),
Some(get_log_name("it_works_basic")),
);
g.with_persistence_options(pparams);
let (a, b, c) = g.migrate(|mig| {
Expand Down Expand Up @@ -379,13 +387,14 @@ fn it_works_with_arithmetic_aliases() {

#[test]
fn it_recovers_persisted_logs() {
let log_name = get_log_name("it_recovers_persisted_logs");
let setup = || {
let mut g = ControllerBuilder::default().build_inner();
let pparams = PersistenceParameters::new(
DurabilityMode::DeleteOnExit,
128,
time::Duration::from_millis(1),
Some(String::from("it_recovers_persisted_logs")),
Duration::from_millis(1),
Some(log_name.clone()),
);
g.with_persistence_options(pparams);

Expand Down Expand Up @@ -436,13 +445,14 @@ fn it_recovers_persisted_logs() {

#[test]
fn it_recovers_persisted_logs_w_multiple_nodes() {
let log_name = get_log_name("it_recovers_persisted_logs_w_multiple_nodes");
let setup = || {
let mut g = ControllerBuilder::default().build_inner();
let pparams = PersistenceParameters::new(
DurabilityMode::DeleteOnExit,
128,
time::Duration::from_millis(1),
Some(String::from("it_recovers_persisted_logs_w_multiple_nodes")),
Duration::from_millis(1),
Some(log_name.clone()),
);
g.with_persistence_options(pparams);

Expand Down Expand Up @@ -493,13 +503,14 @@ fn it_recovers_persisted_logs_w_multiple_nodes() {

#[test]
fn it_recovers_persisted_logs_w_transactions() {
let log_name = get_log_name("it_recovers_persisted_logs");
let setup = || {
let mut g = ControllerBuilder::default().build_inner();
let pparams = PersistenceParameters::new(
DurabilityMode::DeleteOnExit,
128,
time::Duration::from_millis(1),
Some(String::from("it_recovers_persisted_logs_w_transactions")),
Duration::from_millis(1),
Some(log_name.clone()),
);
g.with_persistence_options(pparams);

Expand Down

0 comments on commit 458f854

Please sign in to comment.