Skip to content

Commit

Permalink
cargo: update to fail 0.3 (tikv#261)
Browse files Browse the repository at this point in the history
* cargo: update to fail 0.3

* raft: align failpoints feature naming

This aligns feature naming to use `failpoints` everywhere, like the
underlying library.

* tests/failpoints: use fail scenario
  • Loading branch information
Luca Bruno authored and Hoverbear committed Jul 16, 2019
1 parent 423476c commit 5ffa60e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ script:
# Validate benches still work.
- cargo bench --all -- --test
# Because failpoints inject failure in code path, which will affect all concurrently running tests, Hence they need to be synchronized, which make tests slow.
- cargo test --tests --features failpoint -- --nocapture
- cargo test --tests --features failpoints -- --nocapture
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ members = ["proto"]
[features]
default = []
# Enable failpoints
failpoint = ["fail"]
failpoints = ["fail/failpoints"]

# Make sure to synchronize updates with Harness.
[dependencies]
Expand All @@ -33,7 +33,7 @@ quick-error = "1.2.2"
raft-proto = { path = "proto" }
rand = "0.7.0"
hashbrown = "0.5"
fail = { version = "0.2", optional = true }
fail = { version = "0.3", optional = true }
getset = "0.0.7"
slog-stdlog = "3.0.2"
slog-term = "2.4.0"
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ before taking old, removed peers offline.
#![deny(missing_docs)]
#![recursion_limit = "128"]

#[cfg(feature = "failpoint")]
#[cfg(feature = "failpoints")]
#[macro_use]
extern crate fail;

Expand Down
2 changes: 1 addition & 1 deletion src/raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ impl<T: Storage> Raft<T> {
return Ok(());
}

#[cfg(feature = "failpoint")]
#[cfg(feature = "failpoints")]
fail_point!("before_step");

match m.msg_type() {
Expand Down
22 changes: 4 additions & 18 deletions tests/failpoint_cases/mod.rs → tests/failpoints_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,13 @@ use fail;
use raft::eraftpb::MessageType;
use std::sync::*;

lazy_static! {
/// Failpoints are global structs, hence rules set in different cases
/// may affect each other. So use a global lock to synchronize them.
static ref LOCK: Mutex<()> = {
Mutex::new(())
};
}

fn setup<'a>() -> MutexGuard<'a, ()> {
// We don't want a failed test breaks others.
let guard = LOCK.lock().unwrap_or_else(|e| e.into_inner());
fail::teardown();
fail::setup();
guard
}

// test_reject_stale_term_message tests that if a server receives a request with
// a stale term number, it rejects the request.
// Our implementation ignores the request instead.
// Reference: section 5.1
#[test]
fn test_reject_stale_term_message() {
let _guard = setup();
let scenario = fail::FailScenario::setup();
let l = testing_logger().new(o!("test" => "test_reject_stale_term_message"));
let mut r = new_test_raft(1, vec![1, 2, 3], 10, 1, new_storage(), &l);
fail::cfg("before_step", "panic").unwrap();
Expand All @@ -48,18 +32,20 @@ fn test_reject_stale_term_message() {
let mut m = new_message(0, 0, MessageType::MsgAppend, 0);
m.term = r.term - 1;
r.step(m).expect("");
scenario.teardown();
}

// ensure that the Step function ignores the message from old term and does not pass it to the
// actual stepX function.
#[test]
fn test_step_ignore_old_term_msg() {
let _guard = setup();
let scenario = fail::FailScenario::setup();
let l = testing_logger().new(o!("test" => "test_step_ignore_old_term_msg"));
let mut sm = new_test_raft(1, vec![1], 10, 1, new_storage(), &l);
fail::cfg("before_step", "panic").unwrap();
sm.term = 2;
let mut m = new_message(0, 0, MessageType::MsgAppend, 0);
m.term = 1;
sm.step(m).expect("");
scenario.teardown();
}
10 changes: 5 additions & 5 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// limitations under the License.

#![cfg_attr(not(feature = "cargo-clippy"), allow(unknown_lints))]
#![cfg_attr(feature = "failpoint", allow(dead_code, unused_imports))]
#![cfg_attr(feature = "failpoints", allow(dead_code, unused_imports))]

#[macro_use]
extern crate slog;

#[cfg(feature = "failpoint")]
#[cfg(feature = "failpoints")]
#[macro_use]
extern crate lazy_static;

Expand Down Expand Up @@ -85,8 +85,8 @@ macro_rules! map {
};
}

#[cfg(feature = "failpoint")]
mod failpoint_cases;
#[cfg(not(feature = "failpoint"))]
#[cfg(feature = "failpoints")]
mod failpoints_cases;
#[cfg(not(feature = "failpoints"))]
mod integration_cases;
mod test_util;

0 comments on commit 5ffa60e

Please sign in to comment.