use std::path::PathBuf;
use std::process::Command;
fn zccache_bin() -> PathBuf {
PathBuf::from(env!("CARGO_BIN_EXE_zccache"))
}
fn unreachable_endpoint() -> String {
let pid = std::process::id();
let nonce = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|d| d.as_nanos())
.unwrap_or(0);
#[cfg(windows)]
{
format!(r"\\.\pipe\zccache-issue150-{pid}-{nonce}")
}
#[cfg(unix)]
{
let tmp = std::env::temp_dir();
tmp.join(format!("zccache-issue150-{pid}-{nonce}.sock"))
.to_string_lossy()
.into_owned()
}
}
#[test]
#[ignore]
fn session_end_with_unreachable_daemon_is_idempotent() {
let bin = zccache_bin();
let endpoint = unreachable_endpoint();
let output = Command::new(&bin)
.arg("session-end")
.arg("00000000-0000-0000-0000-000000000000")
.arg("--endpoint")
.arg(&endpoint)
.output()
.expect("failed to run zccache session-end");
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
output.status.success(),
"session-end against unreachable daemon should exit 0 (issue #150). \
exit={:?} stdout={stdout} stderr={stderr}",
output.status.code(),
);
assert!(
stderr.contains("daemon unreachable"),
"expected 'daemon unreachable' warning on stderr, got: {stderr}"
);
}