Skip to content

Commit

Permalink
chore: proper waits
Browse files Browse the repository at this point in the history
  • Loading branch information
zeeshanlakhani committed Jul 21, 2023
1 parent c157267 commit feccc9d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions homestar-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ rand = { workspace = true }
retry = "2.0"
serial_test = "2.0"
tokio-tungstenite = "0.19"
wait-timeout = "0.2"

[features]
default = ["ipfs", "websocket-server"]
Expand Down
2 changes: 1 addition & 1 deletion homestar-runtime/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn init(writer: NonBlocking, guard: WorkerGuard) -> WorkerGuard {
});

#[cfg(all(feature = "console", tokio_unstable))]
filter
let filter = filter
.add_directive("tokio=trace".parse().expect(DIRECTIVE_EXPECT))
.add_directive("runtime=trace".parse().expect(DIRECTIVE_EXPECT));

Expand Down
25 changes: 19 additions & 6 deletions homestar-runtime/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use std::{
net::{IpAddr, Ipv6Addr, Shutdown, SocketAddr, TcpStream},
path::PathBuf,
process::{Command, Stdio},
time::Duration,
};
use wait_timeout::ChildExt;

static BIN: Lazy<PathBuf> = Lazy::new(|| assert_cmd::cargo::cargo_bin(crate_name!()));

Expand Down Expand Up @@ -159,9 +161,21 @@ fn test_server_serial() -> Result<()> {
.stderr(predicate::str::contains("Connection refused"));

let _ = Command::new(BIN.as_os_str()).arg("stop").output();
homestar_proc.try_wait().unwrap();

Ok(())
match homestar_proc.try_wait() {
Ok(Some(_)) => Ok(()),
Ok(None) => {
let _status_code = match homestar_proc.wait_timeout(Duration::from_secs(1)).unwrap() {
Some(status) => status.code(),
None => {
homestar_proc.kill().unwrap();
homestar_proc.wait().unwrap().code()
}
};
Ok(())
}
Err(_e) => Ok(()),
}
}

#[test]
Expand Down Expand Up @@ -198,10 +212,9 @@ fn test_daemon_serial() -> Result<()> {
.stdout(predicate::str::contains("::1"))
.stdout(predicate::str::contains("pong"));

let result = signal::kill(Pid::from_raw(pid), Signal::SIGTERM);
if let Err(err) = result {
panic!("Homestar server/runtime failed to be shutdown via SIGTERM: {err}");
}
let _result = signal::kill(Pid::from_raw(pid), Signal::SIGTERM);

Command::new(BIN.as_os_str()).arg("ping").assert().failure();

Ok(())
}

0 comments on commit feccc9d

Please sign in to comment.