Add testing for beacon node and validator client CLI flags (#2311)

## Issue Addressed

N/A

## Proposed Changes

Add unit tests for the various CLI flags associated with the beacon node and validator client. These changes require the addition of two new flags: `dump-config` and `immediate-shutdown`.

## Additional Info

Both `dump-config` and `immediate-shutdown` are marked as hidden since they should only be used in testing and other advanced use cases.
**Note:** This requires changing `main.rs` so that the flags can adjust the program behavior as necessary.

Co-authored-by: Paul Hauner <paul@paulhauner.com>
This commit is contained in:
Mac L
2021-05-06 00:36:22 +00:00
parent 4cc613d644
commit bacc38c3da
16 changed files with 1327 additions and 47 deletions

View File

@@ -6,6 +6,24 @@ use slog::{debug, o, trace};
use std::sync::Weak;
use tokio::runtime::Runtime;
/// Provides a reason when Lighthouse is shut down.
#[derive(Copy, Clone, Debug)]
pub enum ShutdownReason {
/// The node shut down successfully.
Success(&'static str),
/// The node shut down due to an error condition.
Failure(&'static str),
}
impl ShutdownReason {
pub fn message(&self) -> &'static str {
match self {
ShutdownReason::Success(msg) => msg,
ShutdownReason::Failure(msg) => msg,
}
}
}
/// A wrapper over a runtime handle which can spawn async and blocking tasks.
#[derive(Clone)]
pub struct TaskExecutor {
@@ -17,7 +35,7 @@ pub struct TaskExecutor {
/// continue they can request that everything shuts down.
///
/// The task must provide a reason for shutting down.
signal_tx: Sender<&'static str>,
signal_tx: Sender<ShutdownReason>,
log: slog::Logger,
}
@@ -31,7 +49,7 @@ impl TaskExecutor {
runtime: Weak<Runtime>,
exit: exit_future::Exit,
log: slog::Logger,
signal_tx: Sender<&'static str>,
signal_tx: Sender<ShutdownReason>,
) -> Self {
Self {
runtime,
@@ -255,7 +273,7 @@ impl TaskExecutor {
}
/// Get a channel to request shutting down.
pub fn shutdown_sender(&self) -> Sender<&'static str> {
pub fn shutdown_sender(&self) -> Sender<ShutdownReason> {
self.signal_tx.clone()
}