feat(test): own process startup and cleanup

This commit is contained in:
slhx agent
2026-07-13 10:18:01 +02:00
parent 6b4bb97aaa
commit 7259dd6e33
5 changed files with 108 additions and 28 deletions
+16 -27
View File
@@ -1,13 +1,13 @@
use hemx_axum::runtime_js_path;
use hemx_test::{inspect_wire, EffectInspector};
use hemx_test::{inspect_wire, EffectInspector, TestProcess};
use hemx_workout_example::ui::BUILD_FINGERPRINT;
use std::io::{Read, Write};
use std::net::{TcpListener, TcpStream};
use std::process::{Child, Command, Stdio};
use std::time::{Duration, Instant};
use std::process::Command;
use std::time::Duration;
struct Server {
child: Child,
_process: TestProcess,
addr: String,
}
@@ -17,31 +17,20 @@ impl Server {
let addr = listener.local_addr().unwrap().to_string();
drop(listener);
let bin = env!("CARGO_BIN_EXE_hemx-workout-example");
let mut child = Command::new(bin)
.env("HEMX_WORKOUT_ADDR", &addr)
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.expect("start hemx-workout-example");
let mut command = Command::new(env!("CARGO_BIN_EXE_hemx-workout-example"));
command.env("HEMX_WORKOUT_ADDR", &addr);
let process = TestProcess::start(
command,
"hemx-workout-example",
&addr,
Duration::from_secs(5),
)
.expect("start ready hemx-workout-example");
let deadline = Instant::now() + Duration::from_secs(5);
while Instant::now() < deadline {
if TcpStream::connect(&addr).is_ok() {
return Self { child, addr };
}
std::thread::sleep(Duration::from_millis(25));
Self {
_process: process,
addr,
}
let _ = child.kill();
let _ = child.wait();
panic!("hemx-workout-example did not listen on {addr}");
}
}
impl Drop for Server {
fn drop(&mut self) {
let _ = self.child.kill();
let _ = self.child.wait();
}
}