-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests trigger shotover shutdown and then unwrap the result of the joi…
…n handle (#139)
- Loading branch information
Showing
14 changed files
with
208 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,48 @@ | ||
use anyhow::Result; | ||
use shotover_proxy::runner::{ConfigOpts, Runner}; | ||
use tokio::runtime::Runtime; | ||
use tokio::sync::broadcast; | ||
use tokio::task::JoinHandle; | ||
|
||
pub fn run_shotover_with_topology(topology_path: &str) -> (Runtime, JoinHandle<Result<()>>) { | ||
let opts = ConfigOpts { | ||
topology_file: topology_path.into(), | ||
config_file: "config/config.yaml".into(), | ||
..ConfigOpts::default() | ||
}; | ||
let spawn = Runner::new(opts).unwrap().run_spawn(); | ||
pub struct ShotoverManager { | ||
pub runtime: Runtime, | ||
pub handle: Option<JoinHandle<Result<()>>>, | ||
pub trigger_shutdown_tx: broadcast::Sender<()>, | ||
} | ||
|
||
impl ShotoverManager { | ||
pub fn from_topology_file(topology_path: &str) -> ShotoverManager { | ||
let opts = ConfigOpts { | ||
topology_file: topology_path.into(), | ||
config_file: "config/config.yaml".into(), | ||
..ConfigOpts::default() | ||
}; | ||
let spawn = Runner::new(opts).unwrap().run_spawn(); | ||
|
||
// If we allow the tracing_guard to be dropped then the following tests in the same file will not get tracing so we mem::forget it. | ||
// This is because tracing can only be initialized once in the same execution, secondary attempts to initalize tracing will silently fail. | ||
std::mem::forget(spawn.tracing_guard); | ||
|
||
ShotoverManager { | ||
runtime: spawn.runtime, | ||
handle: Some(spawn.handle), | ||
trigger_shutdown_tx: spawn.trigger_shutdown_tx, | ||
} | ||
} | ||
} | ||
|
||
// If we allow the tracing_guard to be dropped then the following tests in the same file will not get tracing so we mem::forget it. | ||
// This is because tracing can only be initialized once in the same execution, secondary attempts to initalize tracing will silently fail. | ||
std::mem::forget(spawn.tracing_guard); | ||
(spawn.runtime, spawn.handle) | ||
impl Drop for ShotoverManager { | ||
fn drop(&mut self) { | ||
if std::thread::panicking() { | ||
// If already panicking do nothing in order to avoid a double panic. | ||
// We only shutdown shotover to test the shutdown process not because we need to clean up any resources. | ||
// So skipping shutdown on panic is fine. | ||
} else { | ||
self.trigger_shutdown_tx.send(()).unwrap(); | ||
self.runtime | ||
.block_on(self.handle.take().unwrap()) | ||
.unwrap() | ||
.unwrap(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.