Add background forwarding mode
ci / test (push) Has been cancelled
ci / remote-bench (push) Has been cancelled

This commit is contained in:
DuProcess
2026-06-13 15:55:14 -04:00
parent da16588bc5
commit 6d1e9d3065
2 changed files with 137 additions and 2 deletions
+53
View File
@@ -626,6 +626,59 @@ fn native_local_forward_echo_smoke() {
);
}
#[test]
fn native_local_forward_background_smoke() {
let dir = tempfile::tempdir().unwrap();
let port = free_udp_port();
let config = write_server_config(&dir, port);
write_native_client_auth(&dir, &config);
let echo_port = start_echo_server();
let local_port = free_tcp_port();
let pid_file = dir.path().join("background.pid");
let mut server = start_server(&dir, &config);
let client_bin = env!("CARGO_BIN_EXE_dosh-client");
let output = Command::new(client_bin)
.arg("--auth")
.arg("native")
.arg("--no-cache")
.arg("-f")
.arg("-N")
.arg("-L")
.arg(format!("{local_port}:127.0.0.1:{echo_port}"))
.arg("--session")
.arg("default")
.arg("--dosh-host")
.arg("127.0.0.1")
.arg("--dosh-port")
.arg(port.to_string())
.arg("local")
.env("HOME", dir.path())
.env("DOSH_BACKGROUND_PID_FILE", &pid_file)
.output()
.unwrap();
assert!(
output.status.success(),
"stderr={}",
String::from_utf8_lossy(&output.stderr)
);
let mut stream = TcpStream::connect(("127.0.0.1", local_port)).unwrap();
stream
.set_read_timeout(Some(Duration::from_secs(3)))
.unwrap();
stream.write_all(b"dosh-background-forward-ping").unwrap();
let mut buf = [0u8; 64];
let n = stream.read(&mut buf).unwrap();
if let Ok(pid) = fs::read_to_string(&pid_file) {
let _ = Command::new("kill").arg(pid.trim()).status();
}
let _ = server.kill();
let _ = server.wait();
assert_eq!(&buf[..n], b"dosh-background-forward-ping");
}
#[test]
fn native_remote_forward_echo_smoke() {
let dir = tempfile::tempdir().unwrap();