test: readiness signals replace sleep-based timing (N4)
- signal tests use a marker-file readiness signal: the child's command is 'echo ready > <marker>; exec sleep 60', the test polls wait_for_file(marker, 5s) — marker exists = the shell exec'd, so the signal lands on the real target regardless of machine load. Applied in tests/pty.rs (both signal tests), tests/pipe.rs (SIGTERM), and the src/local unit tests; wait_for_file lives in tests/common. - cancel-cleanup post-action sleeps became bounded polls for the child's death (kill(pid,0) -> ESRCH, 5s deadline) — faster and flake-proof in both directions. - resize/cat-stdin tests need no readiness signal at all: the adapter's input pump processes chunks in order — the sleeps there were pure latency (integration suites now ~40ms, was 200-270ms).
This commit is contained in:
1 parent
a73484203e
commit
cdd6893046
6 files changed
+241
-61
No files matched your search
+21
-2
@@ -16,6 +16,7 @@
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use alkcall::core::auth::Identity;
|
||||
use alktty::adapter::drive_session;
|
||||
@@ -297,6 +298,24 @@ pub fn nanos_seed() -> u64 {
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.map(|d| d.as_nanos() as u64)
|
||||
.unwrap_or(0)
|
||||
.expect("clock went backwards")
|
||||
.as_nanos() as u64
|
||||
}
|
||||
|
||||
/// Poll until `path` exists (or `timeout` elapses), sleeping 10 ms
|
||||
/// between probes. This is the readiness signal for tests that need
|
||||
/// the child to have reached a state (e.g. `exec`'d) before acting on
|
||||
/// it — replaces fixed pre-action sleeps, which fail spuriously on a
|
||||
/// loaded machine (review #001 N4). Returns `false` on timeout.
|
||||
pub async fn wait_for_file(path: &std::path::Path, timeout: Duration) -> bool {
|
||||
let deadline = tokio::time::Instant::now() + timeout;
|
||||
loop {
|
||||
if path.exists() {
|
||||
return true;
|
||||
}
|
||||
if tokio::time::Instant::now() >= deadline {
|
||||
return false;
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(10)).await;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user