feat(test): own process startup and cleanup
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user