Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine CI script to ensure correctness. #15

Merged
merged 4 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
dist: trusty
sudo: false
language: rust
os:
- linux
- osx
sudo: false
env:
global:
- RUST_BACKTRACE=1
- RUSTFLAGS="-D warnings"
cache: cargo

rust:
- stable
- beta
- nightly

matrix:
allow_failures:
- rust: nightly
include:
# This build uses stable and checks rustfmt (clippy is not on stable).
- rust: stable
install:
- rustup component add rustfmt-preview
before_script:
- cargo fmt --all -- --check
- rust: nightly
install:
- rustup component add clippy-preview --toolchain nightly
before_script:
- cargo clippy --all -- -D clippy::all


script:
- if [[ $TRAVIS_RUST_VERSION == "nightly" ]]; then rustup component add clippy-preview && cargo clippy; fi
- export RUSTFLAGS=-Dwarnings
- cargo build
- cargo test --all
- cargo test --all -- --nocapture
# Validate benches still work.
- cargo bench --all -- --test
28 changes: 15 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
//!
//! If you want to disable all the fail points at compile time, you can enable features `no_fail`.
#![deny(missing_docs, missing_debug_implementations)]
#![cfg_attr(feature = "cargo-clippy", feature(tool_lints))]

#[macro_use]
extern crate lazy_static;
Expand All @@ -66,8 +67,8 @@ use std::env::VarError;
use std::str::FromStr;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Condvar, Mutex, RwLock, TryLockError};
use std::{env, thread};
use std::time::{Duration, Instant};
use std::{env, thread};

use rand::Closed01;

Expand Down Expand Up @@ -118,8 +119,8 @@ impl PartialEq for Action {
impl Action {
fn new(task: Task, freq: f32, max_cnt: Option<usize>) -> Action {
Action {
task: task,
freq: freq,
task,
freq,
count: max_cnt.map(AtomicUsize::new),
}
}
Expand Down Expand Up @@ -171,7 +172,7 @@ impl FromStr for Action {
let (first, second) = partition(remain, '(');
if let Some(second) = second {
remain = first;
if !second.ends_with(")") {
if !second.ends_with(')') {
return Err("parentheses not match".to_owned());
}
args = Some(&second[..second.len() - 1]);
Expand All @@ -198,9 +199,9 @@ impl FromStr for Action {
}

let parse_timeout = || match args {
None => return Err("sleep require timeout".to_owned()),
None => Err("sleep require timeout".to_owned()),
Some(timeout_str) => match timeout_str.parse() {
Err(e) => return Err(format!("failed to parse timeout: {}", e)),
Err(e) => Err(format!("failed to parse timeout: {}", e)),
Ok(timeout) => Ok(timeout),
},
};
Expand Down Expand Up @@ -228,6 +229,7 @@ struct FailPoint {
actions_str: RwLock<String>,
}

#[cfg_attr(feature = "cargo-clippy", allow(clippy::mutex_atomic))]
impl FailPoint {
fn new() -> FailPoint {
FailPoint {
Expand All @@ -250,13 +252,13 @@ impl FailPoint {
}
Err(e) => panic!("unexpected poison: {:?}", e),
}

let mut guard = self.pause.lock().unwrap();
*guard = false;
self.pause_notifier.notify_all();
}
}

#[cfg_attr(feature = "cargo-clippy", allow(clippy::option_option))]
fn eval(&self, name: &str) -> Option<Option<String>> {
let task = {
let actions = self.actions.read().unwrap();
Expand Down Expand Up @@ -326,7 +328,7 @@ pub fn setup() {
Err(VarError::NotPresent) => return,
Err(e) => panic!("invalid failpoints: {:?}", e),
};
for mut cfg in failpoints.trim().split(";") {
for mut cfg in failpoints.trim().split(';') {
cfg = cfg.trim();
if cfg.trim().is_empty() {
continue;
Expand All @@ -344,7 +346,7 @@ pub fn setup() {
/// All the paused fail points will be notified before they are deactivated.
pub fn teardown() {
let mut registry = REGISTRY.registry.write().unwrap();
for (_, p) in &*registry {
for p in registry.values() {
// wake up all pause failpoint.
p.set_actions("", vec![]);
}
Expand All @@ -358,9 +360,7 @@ pub fn list() -> Vec<(String, String)> {
let registry = REGISTRY.registry.read().unwrap();
registry
.iter()
.map(|(name, fp)| {
(name.to_string(), fp.actions_str.read().unwrap().clone())
})
.map(|(name, fp)| (name.to_string(), fp.actions_str.read().unwrap().clone()))
.collect()
}

Expand Down Expand Up @@ -685,7 +685,9 @@ mod tests {
assert_eq!(f1(), 1);

let (tx, rx) = mpsc::channel();
thread::spawn(move || { tx.send(f2()).unwrap(); });
thread::spawn(move || {
tx.send(f2()).unwrap();
});
assert!(rx.recv_timeout(Duration::from_millis(500)).is_err());

teardown();
Expand Down
13 changes: 5 additions & 8 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ fn test_off() {
#[test]
fn test_return() {
let f = || {
fail_point!("return", |s: Option<String>| {
s.map_or(2, |s| s.parse().unwrap())
});
fail_point!("return", |s: Option<String>| s
.map_or(2, |s| s.parse().unwrap()));
0
};
assert_eq!(f(), 0);
Expand Down Expand Up @@ -159,9 +158,8 @@ fn test_delay() {
#[test]
fn test_freq_and_count() {
let f = || {
fail_point!("freq_and_count", |s: Option<String>| {
s.map_or(2, |s| s.parse().unwrap())
});
fail_point!("freq_and_count", |s: Option<String>| s
.map_or(2, |s| s.parse().unwrap()));
0
};
fail::cfg(
Expand Down Expand Up @@ -192,8 +190,7 @@ fn test_condition() {

#[test]
fn test_list() {
assert!(!fail::list()
.contains(&("list".to_string(), "off".to_string())));
assert!(!fail::list().contains(&("list".to_string(), "off".to_string())));
fail::cfg("list", "off").unwrap();
assert!(fail::list().contains(&("list".to_string(), "off".to_string())));
fail::cfg("list", "return").unwrap();
Expand Down