Skip to content

Commit

Permalink
Small cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbornholt committed May 19, 2022
1 parent e5d8a9f commit 71b8ad2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
16 changes: 11 additions & 5 deletions src/runtime/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::scheduler::metrics::MetricsScheduler;
use crate::scheduler::{Schedule, Scheduler};
use crate::Config;
use std::cell::RefCell;
use std::fmt;
use std::panic;
use std::rc::Rc;
use std::sync::atomic::{AtomicBool, Ordering};
Expand Down Expand Up @@ -64,8 +65,6 @@ impl<S: Scheduler + 'static> Runner<S> {
let execution = Execution::new(self.scheduler.clone(), schedule);
let f = Arc::clone(&f);

#[allow(clippy::redundant_closure)]
// Clippy is wrong: https://github.com/rust-lang/rust-clippy/issues/8073
span!(Level::INFO, "execution", i).in_scope(|| execution.run(&self.config, move || f()));

i += 1;
Expand All @@ -78,7 +77,6 @@ impl<S: Scheduler + 'static> Runner<S> {
/// A `PortfolioRunner` is the same as a `Runner`, except that it can run multiple different
/// schedulers (a "portfolio" of schedulers) in parallel. If any of the schedulers finds a failing
/// execution of the test, the entire run fails.
#[derive(Debug)]
pub struct PortfolioRunner {
schedulers: Vec<Box<dyn Scheduler + Send + 'static>>,
stop_on_first_failure: bool,
Expand Down Expand Up @@ -135,8 +133,6 @@ impl PortfolioRunner {
let runner = Runner::new(scheduler, config);

span!(Level::INFO, "job", i).in_scope(|| {
#[allow(clippy::redundant_closure)]
// Clippy is wrong: https://github.com/rust-lang/rust-clippy/issues/8073
let ret = panic::catch_unwind(panic::AssertUnwindSafe(|| runner.run(move || f())));

match ret {
Expand Down Expand Up @@ -174,6 +170,16 @@ impl PortfolioRunner {
}
}

impl fmt::Debug for PortfolioRunner {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("PortfolioRunner")
.field("schedulers", &self.schedulers.len())
.field("stop_on_first_failure", &self.stop_on_first_failure)
.field("config", &self.config)
.finish()
}
}

/// A wrapper around a `Scheduler` that can be told to stop early by setting a flag. We use this to
/// abort all jobs in a `PortfolioRunner` as soon as any job fails.
#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/scheduler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl Schedule {
/// state and strategically explore different schedules. At the start of each test execution, the
/// executor calls `new_execution()` to inform the scheduler that a new execution is starting. Then,
/// for each scheduling decision, the executor calls `next_task` to determine which task to run.
pub trait Scheduler: Debug {
pub trait Scheduler {
/// Inform the `Scheduler` that a new execution is about to begin. If this function returns
/// None, the test will end rather than performing another execution. If it returns
/// `Some(schedule)`, the returned `Schedule` can be used to initialize a `ReplayScheduler` for
Expand Down
6 changes: 1 addition & 5 deletions tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ where
let mut config = Config::new();
config.failure_persistence = FailurePersistence::Print;
let runner = Runner::new(scheduler, config);
#[allow(clippy::redundant_closure)] // Clippy is wrong: https://github.com/rust-lang/rust-clippy/issues/8073
runner.run(move || test_func())
})
.expect_err("test should panic")
Expand All @@ -42,8 +41,7 @@ where
config.failure_persistence = FailurePersistence::Print;
let scheduler = ReplayScheduler::new_from_encoded(&schedule);
let runner = Runner::new(scheduler, config);
#[allow(clippy::redundant_closure)]
// Clippy is wrong: https://github.com/rust-lang/rust-clippy/issues/8073

runner.run(move || test_func());
})
.expect_err("replay should panic")
Expand Down Expand Up @@ -74,7 +72,6 @@ where
let mut config = Config::new();
config.failure_persistence = FailurePersistence::File(Some(tempdir_path));
let runner = Runner::new(scheduler, config);
#[allow(clippy::redundant_closure)] // Clippy is wrong: https://github.com/rust-lang/rust-clippy/issues/8073
runner.run(move || test_func())
})
.expect_err("test should panic")
Expand All @@ -86,7 +83,6 @@ where
// to test the `replay_from_file` function directly, so this time we'll default to printing the
// schedule to stdout.
let result = {
#[allow(clippy::redundant_closure)] // Clippy is wrong: https://github.com/rust-lang/rust-clippy/issues/8073
panic::catch_unwind(move || replay_from_file(move || test_func(), schedule_file))
.expect_err("replay should panic")
};
Expand Down

0 comments on commit 71b8ad2

Please sign in to comment.