Skip to content

Commit

Permalink
fix: make devfed exit immediatelly if a signal is received
Browse files Browse the repository at this point in the history
  • Loading branch information
douglaz committed Jul 27, 2023
1 parent 02e5d0e commit 7e67914
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions devimint/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ use std::str::FromStr;

use fedimint_core::encoding::Decodable;

async fn setup(arg: CommonArgs) -> Result<(ProcessManager, TaskGroup)> {
async fn setup(arg: CommonArgs) -> Result<ProcessManager> {
let globals = vars::Global::new(&arg.test_dir, arg.fed_size).await?;
let log_file = fs::OpenOptions::new()
.write(true)
Expand All @@ -1114,59 +1114,62 @@ async fn setup(arg: CommonArgs) -> Result<(ProcessManager, TaskGroup)> {
write_overwrite_async(globals.FM_TEST_DIR.join("env"), env_string).await?;
info!("Test setup in {:?}", globals.FM_DATA_DIR);
let process_mgr = ProcessManager::new(globals);
let task_group = TaskGroup::new();
task_group.install_kill_handler();
Ok((process_mgr, task_group))
Ok(process_mgr)
}

#[tokio::main]
async fn main() -> Result<()> {
let args = Args::parse();
match args.command {
Cmd::ExternalDaemons => {
let (process_mgr, task_group) = setup(args.common).await?;
let process_mgr = setup(args.common).await?;
let task_group = TaskGroup::new();
task_group.install_kill_handler();
let _daemons =
write_ready_file(&process_mgr.globals, external_daemons(&process_mgr).await)
.await?;
task_group.make_handle().make_shutdown_rx().await.await?;
}
Cmd::DevFed => {
let (process_mgr, task_group) = setup(args.common).await?;
let process_mgr = setup(args.common).await?;
let dev_fed = dev_fed(&process_mgr).await?;
dev_fed.fed.pegin(10_000).await?;
dev_fed.fed.pegin_gateway(20_000, &dev_fed.gw_cln).await?;
dev_fed.fed.pegin_gateway(20_000, &dev_fed.gw_lnd).await?;
let _daemons = write_ready_file(&process_mgr.globals, Ok(dev_fed)).await?;
task_group.make_handle().make_shutdown_rx().await.await?;
// Don't use task_group here as we want to shut down immediately if
// a kill signal is received
}
Cmd::RunUi => {
let (process_mgr, task_group) = setup(args.common).await?;
let process_mgr = setup(args.common).await?;
let task_group = TaskGroup::new();
task_group.install_kill_handler();
let fedimintds = run_ui(&process_mgr).await?;
let _daemons = write_ready_file(&process_mgr.globals, Ok(fedimintds)).await?;
task_group.make_handle().make_shutdown_rx().await.await?;
}
Cmd::LatencyTests => {
let (process_mgr, _) = setup(args.common).await?;
let process_mgr = setup(args.common).await?;
let dev_fed = dev_fed(&process_mgr).await?;
latency_tests(dev_fed).await?;
}
Cmd::ReconnectTest => {
let (process_mgr, _) = setup(args.common).await?;
let process_mgr = setup(args.common).await?;
let dev_fed = dev_fed(&process_mgr).await?;
reconnect_test(dev_fed, &process_mgr).await?;
}
Cmd::CliTests => {
let (process_mgr, _) = setup(args.common).await?;
let process_mgr = setup(args.common).await?;
let dev_fed = dev_fed(&process_mgr).await?;
cli_tests(dev_fed).await?;
}
Cmd::LoadTestToolTest => {
let (process_mgr, _) = setup(args.common).await?;
let process_mgr = setup(args.common).await?;
let dev_fed = dev_fed(&process_mgr).await?;
cli_load_test_tool_test(dev_fed).await?;
}
Cmd::LightningReconnectTest => {
let (process_mgr, _) = setup(args.common).await?;
let process_mgr = setup(args.common).await?;
let dev_fed = dev_fed(&process_mgr).await?;
lightning_gw_reconnect_test(dev_fed, &process_mgr).await?;
}
Expand Down

0 comments on commit 7e67914

Please sign in to comment.