Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e390a62
feat(testkit): #3062 deadline helpers and a test watchdog
THEtheChad Oct 26, 2026
0dfab57
test(ui-egui): #3062 every headless test is watched
THEtheChad Oct 26, 2026
c609da9
test: #3062 give the unbounded test waits in ui-egui, gpu and preview…
THEtheChad Oct 26, 2026
5437b5d
docs: #3062 test deadlines, LIGHTCRAFT_TIME_SCALE and the test watchdog
THEtheChad Oct 26, 2026
05471f3
fix(testkit): #3062 the watchdog's thread owns the hard deadline
THEtheChad Oct 26, 2026
bfe7fac
fix(testkit): #3062 a shorter grace period for the watchdog's own abo…
THEtheChad Oct 26, 2026
08e1dc1
docs: #3062 the README says which tests the watchdog covers
THEtheChad Oct 30, 2026
07af1ef
test(ui-egui): #3062 the rejected-model test records a skip without t…
THEtheChad Oct 30, 2026
12b2509
fix(testkit): #3062 the watchdog tests' kill deadline never shrinks b…
THEtheChad Oct 30, 2026
ee68988
fix(testkit): #3062 setting notes reach stderr even when the test tha…
THEtheChad Oct 30, 2026
9d4471f
fix(testkit): #3062 a configuration note never keeps the watchdog fro…
THEtheChad Oct 30, 2026
0ee3beb
docs: #3062 name the limits LIGHTCRAFT_TIME_SCALE stretches and who r…
THEtheChad Nov 3, 2026
4cb99f4
test: #3062 a held probe's gate wait never shrinks below 60 s
THEtheChad Nov 3, 2026
ceb19d3
fix(testkit): #3062 a watchdog that couldn't start is tried again at …
THEtheChad Nov 3, 2026
fcbd28a
test(ui-egui): #3062 the shutdown integration test is watched too
THEtheChad Nov 3, 2026
17bfc68
test(engine): #3064 the availability cache's caller check holds the p…
THEtheChad Oct 26, 2026
3b692cb
test(fetch): #3064 timeout and cancel bounds stretch with LIGHTCRAFT_…
THEtheChad Oct 26, 2026
ccb7117
test(catalog): #3064 the smart-album chain's time guard stretches wit…
THEtheChad Oct 26, 2026
2a61127
test(raw): #3064 the hostile-dimension time guard stretches with LIGH…
THEtheChad Oct 27, 2026
d5681e1
test(preview): #3064 the pool's no-second-wait checks compare with DR…
THEtheChad Oct 26, 2026
60e4af1
test(ui-egui): #3064 the activity stack's half-second threshold is te…
THEtheChad Oct 26, 2026
d3ff89e
test(engine): #3064 device scans, card set-up and the SAM 3 download …
THEtheChad Oct 26, 2026
1d28747
test(fetch): #3064 timing bounds never shrink below their unscaled va…
THEtheChad Oct 26, 2026
a8d4563
test(preview): #3064 the no-second-wait checks count the pool's waits…
THEtheChad Oct 26, 2026
839218e
test: #3064 gates, regression guards and fixed-pace waits never shrin…
THEtheChad Oct 26, 2026
17056fe
test(engine): #3064 the paused-sweep test gives way only once the fou…
THEtheChad Oct 26, 2026
874062f
test(fetch): #3064 the wait for the resolver to start is as long as t…
THEtheChad Oct 30, 2026
719598b
test(ui-egui): #3064 the sleeping drive wakes when a call's fallback …
THEtheChad Oct 30, 2026
63247d9
test(engine): #3064 the stuck card set-up stays stuck until the test'…
THEtheChad Oct 30, 2026
dd49e63
test(engine): #3064 the second card set-up's answer is bounded too
THEtheChad Oct 30, 2026
ba76a44
test(engine): #3064 the 50 cold device get() calls are bounded again
THEtheChad Nov 3, 2026
23bb5bc
test(fetch): #3064 the cancel test reports a part that never got bytes
THEtheChad Nov 3, 2026
70eb6c5
test(engine): #3064 the warm device get() is bounded like the cold ones
THEtheChad Nov 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,15 @@ adapters per backend, corpus, fonts) and every skip by reason. It writes `target
`target/ci/summary.md`, a block to paste into a PR (`--summary-md` prints it); `--hardware` also runs the
GPU tests on every backend that has a hardware adapter. Nothing is uploaded.

libtest has no per-test timeout either, so test waits go through `lightcraft_testkit::wait_until` and
`recv_within`, which fail the test with what it waited for. `LIGHTCRAFT_TIME_SCALE=3` gives their limits, and
those built with `lightcraft_testkit::scaled`, three times as long on a slow or shared machine; the headless
harness's own timeouts (`Headless::request`, `settle`, `step_until`) don't scale. A watchdog ends a test
binary (exit status 124) when a watched test has run for `LIGHTCRAFT_TEST_WATCHDOG_MIN` minutes (default 30,
times the time scale; `0` turns it off), printing the watched tests still running. The headless tests in
ui-egui's unit tests are watched; any other test, including ui-egui's integration tests in
`crates/ui-egui/tests/`, is watched only when it calls `lightcraft_testkit::watch()`.

**Chinese and Japanese text** need the shared font repo, an optional build input (official releases always include it):

```sh
Expand Down
5 changes: 4 additions & 1 deletion crates/catalog/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,10 @@ fn chains_of_smart_albums_stay_linear() {
}
let start = std::time::Instant::now();
assert_eq!(c.album_count(AlbumId(26)), 20);
assert!(start.elapsed() < std::time::Duration::from_secs(2), "took {:?}", start.elapsed());
// a regression guard, not a speed measurement: linear is microseconds, 2^25 passes take minutes
// (stretched by LIGHTCRAFT_TIME_SCALE for a loaded machine, never shrunk below 2 s)
let limit = lightcraft_testkit::scaled(std::time::Duration::from_secs(2)).max(std::time::Duration::from_secs(2));
assert!(start.elapsed() < limit, "took {:?}", start.elapsed());
}

/// A smart album's own album filter (not only its rules) counts in loops: A filtered to "in A" is
Expand Down
49 changes: 31 additions & 18 deletions crates/engine/src/availability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,27 +300,33 @@ mod tests {
let mut a = Availability::default();
let caller = std::thread::current().id();
let on_caller = Arc::new(AtomicUsize::new(0));
let c = on_caller.clone();
// a sleeping NAS: every check waits until the test opens the gate (or gives up, so a
// broken build fails instead of hanging)
let gate = Arc::new((Mutex::new(false), std::sync::Condvar::new()));
let finished = Arc::new(AtomicUsize::new(0));
let (c, g, f) = (on_caller.clone(), gate.clone(), finished.clone());
a.set_probe(Arc::new(move |p| {
if std::thread::current().id() == caller {
c.fetch_add(1, Ordering::SeqCst);
}
std::thread::sleep(Duration::from_millis(200)); // a sleeping NAS
let (open, cv) = &*g;
let limit = lightcraft_testkit::scaled(Duration::from_secs(5)).max(Duration::from_secs(5));
drop(cv.wait_timeout_while(held(open), limit, |open| !*open).unwrap_or_else(PoisonError::into_inner));
f.fetch_add(1, Ordering::SeqCst);
p == "here"
}));
let woke = Arc::new(AtomicUsize::new(0));
let w = woke.clone();
a.run_in_background(Arc::new(move || {
w.fetch_add(1, Ordering::SeqCst);
}));
let t0 = std::time::Instant::now();
assert_eq!(a.exists("here"), None, "unknown at first");
assert_eq!(a.exists("gone"), None);
assert!(t0.elapsed() < Duration::from_millis(150), "the caller never waits for the probe");
let deadline = std::time::Instant::now() + Duration::from_secs(20);
while (a.exists("here").is_none() || a.exists("gone").is_none()) && std::time::Instant::now() < deadline {
std::thread::sleep(Duration::from_millis(10));
}
// the gate is still shut, so a caller that waited for a check could not have got here yet
assert_eq!(finished.load(Ordering::SeqCst), 0, "the caller never waits for the probe");
*held(&gate.0) = true;
gate.1.notify_all();
wait_until("both answers", || a.exists("here").is_some() && a.exists("gone").is_some());
assert_eq!(a.exists("here"), Some(true));
assert_eq!(a.exists("gone"), Some(false));
// Cache publication precedes its wake callback. Check these two notifications before
Expand All @@ -332,12 +338,10 @@ mod tests {
assert!(a.gone_generation() >= 2);
}

/// Wait for `done` (at most 20 s, stretched by `LIGHTCRAFT_TIME_SCALE`).
#[track_caller]
fn wait_until(what: &str, done: impl Fn() -> bool) {
let deadline = std::time::Instant::now() + Duration::from_secs(20);
while !done() {
assert!(std::time::Instant::now() < deadline, "timed out waiting: {what}");
std::thread::sleep(Duration::from_millis(2));
}
lightcraft_testkit::wait_until(Duration::from_secs(20), what, done);
}

fn held<T>(m: &Mutex<T>) -> MutexGuard<'_, T> {
Expand Down Expand Up @@ -486,12 +490,18 @@ mod tests {
let mut a = Availability::default();
let log = Arc::new(Mutex::new(Vec::<String>::new()));
let l = log.clone();
// the worker is held inside the fourth check until the sweep is told to give way
// the worker is held inside the fourth check (and says it got there) until the sweep is told to
// give way; the hold gives up after a while, so a failed test leaves no worker spinning
let hold = Arc::new(std::sync::atomic::AtomicBool::new(true));
let h = hold.clone();
let entered = Arc::new(std::sync::atomic::AtomicBool::new(false));
let (h, e) = (hold.clone(), entered.clone());
a.set_probe(Arc::new(move |p| {
while p == "sweep 3" && h.load(Ordering::SeqCst) {
std::thread::sleep(Duration::from_millis(1));
if p == "sweep 3" {
e.store(true, Ordering::SeqCst);
let t = std::time::Instant::now();
while h.load(Ordering::SeqCst) && t.elapsed() < lightcraft_testkit::scaled(Duration::from_secs(30)).max(Duration::from_secs(30)) {
std::thread::sleep(Duration::from_millis(1));
}
}
held(&l).push(p.to_string());
true
Expand All @@ -500,9 +510,12 @@ mod tests {
let busy = busy_flag(&a);
busy.store(false, Ordering::SeqCst);
assert!(a.sweep((0..100).map(|i| format!("sweep {i}")).collect()));
wait_until("a few checks", || held(&log).len() >= 3);
// the fourth check has started (so giving way now can't keep it from starting)
wait_until("the worker inside the fourth check", || entered.load(Ordering::SeqCst));
assert_eq!(held(&log).len(), 3);
busy.store(true, Ordering::SeqCst);
hold.store(false, Ordering::SeqCst);
wait_until("the check in flight", || held(&log).len() >= 4);
std::thread::sleep(YIELD_POLL * 2);
let stopped = held(&log).len();
assert_eq!(stopped, 4, "stopped part way, after the check it was in");
Expand Down
47 changes: 36 additions & 11 deletions crates/engine/src/denoise/gpu_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,15 @@ fn a_set_up_runs_beside_the_cpu_and_removes_its_marker() {
let _ = std::fs::remove_dir_all(&dir);
}

/// Opens its gate when dropped, however the test ends.
struct OpenOnDrop(Arc<AtomicBool>);

impl Drop for OpenOnDrop {
fn drop(&mut self) {
self.0.store(true, Ordering::SeqCst);
}
}

#[test]
fn a_set_up_makes_the_folder_of_its_marker() {
let dir = folder("setup-folder").join("not").join("yet");
Expand All @@ -303,22 +312,38 @@ fn a_set_up_makes_the_folder_of_its_marker() {
fn a_set_up_that_takes_too_long_is_given_up_on() {
let dir = folder("slowsetup");
let marker = dir.join(GPU_SETUP_MARKER);
let started = web_time::Instant::now();
let slow = || -> Result<(), String> {
std::thread::sleep(Duration::from_millis(600));
// a card whose set-up is stuck until the test opens the gate, which it does only after its checks
// (or when it fails: `release` opens it on drop, so the set-up thread doesn't spin on)
let gate = Arc::new(AtomicBool::new(false));
let release = OpenOnDrop(gate.clone());
let finished = Arc::new(AtomicBool::new(false));
let (g, f) = (gate.clone(), finished.clone());
let slow = move || -> Result<(), String> {
while !g.load(Ordering::SeqCst) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
std::thread::sleep(Duration::from_millis(1));
}
f.store(true, Ordering::SeqCst);
Ok(())
};
let r = set_up_card(&marker, Duration::from_millis(50), slow, || ());
// each call runs on a helper thread with the deadline on its answer: a set_up_card that waited
// for the stuck card fails the test there instead of hanging it
let answer = |limit: Duration, card: Box<dyn FnOnce() -> Result<(), String> + Send>, what: &str| {
let (tx, rx) = std::sync::mpsc::channel();
let m = marker.clone();
std::thread::spawn(move || {
let _ = tx.send(set_up_card(&m, limit, card, || ()));
});
lightcraft_testkit::recv_within(&rx, Duration::from_secs(30), what)
};
let r = answer(Duration::from_millis(50), Box::new(slow), "set_up_card's answer while the card is stuck");
assert!(r.as_ref().is_err_and(|e| e.contains("took longer") && worth_retrying(e)), "{r:?}");
assert!(started.elapsed() < Duration::from_millis(500), "the caller does not wait for the card");
assert!(!finished.load(Ordering::SeqCst), "the caller does not wait for the card");
// while the first is still stuck, another set-up of the same model does not start a second one
let again = set_up_card(&marker, Duration::from_secs(5), || Ok(()), || ());
assert!(again.is_err_and(|e| e.contains("still setting up") && worth_retrying(&e)));
let again = answer(Duration::from_secs(5), Box::new(|| Ok(())), "a second set-up's answer while the first is stuck");
assert!(again.as_ref().is_err_and(|e| e.contains("still setting up") && worth_retrying(e)), "{again:?}");
// once it ends its marker goes, and the card can be set up again
while marker.exists() {
assert!(started.elapsed() < Duration::from_secs(10), "the stuck set-up ended");
std::thread::sleep(Duration::from_millis(20));
}
drop(release);
lightcraft_testkit::wait_until(Duration::from_secs(10), "the stuck set-up ended and removed its marker", || !marker.exists());
while SETTING_UP.lock().unwrap().iter().any(|m| m == &marker) {
std::thread::sleep(Duration::from_millis(5));
}
Expand Down
30 changes: 22 additions & 8 deletions crates/engine/src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ mod tests {
Device { name: name.into(), path: format!("/v/{name}/DCIM"), root: format!("/v/{name}") }
}

/// Wait (bounded) for `f`.
/// Wait (bounded: 20 s, stretched by `LIGHTCRAFT_TIME_SCALE`) for `f`.
fn until(f: impl Fn() -> bool) -> bool {
let t = std::time::Instant::now();
while t.elapsed() < Duration::from_secs(20) {
while t.elapsed() < lightcraft_testkit::scaled(Duration::from_secs(20)) {
if f() {
return true;
}
Expand All @@ -261,15 +261,21 @@ mod tests {

#[test]
fn slow_scans_never_block_and_hot_plug_still_arrives() {
// a scanner that takes 1.5 s (a sleeping network drive) and counts its runs
const SLOW: Duration = Duration::from_millis(1500);
// a scanner held until the test opens its gate (a sleeping network drive) that counts its runs;
// it gives up after a while so a get() that waits for it fails the test instead of hanging it
let mounted = Arc::new(Mutex::new(Vec::<Device>::new()));
let runs = Arc::new(AtomicUsize::new(0));
let (m, r) = (mounted.clone(), runs.clone());
let finished = Arc::new(AtomicUsize::new(0));
let gate = Arc::new(std::sync::atomic::AtomicBool::new(false));
let (m, r, f, g) = (mounted.clone(), runs.clone(), finished.clone(), gate.clone());
let watch = DeviceWatch::new(
move || {
r.fetch_add(1, Ordering::SeqCst);
std::thread::sleep(SLOW);
let t = std::time::Instant::now();
while !g.load(Ordering::SeqCst) && t.elapsed() < lightcraft_testkit::scaled(Duration::from_secs(5)).max(Duration::from_secs(5)) {
std::thread::sleep(Duration::from_millis(1));
}
f.fetch_add(1, Ordering::SeqCst);
m.lock().unwrap().clone()
},
Duration::from_millis(20),
Expand All @@ -284,17 +290,25 @@ mod tests {
for _ in 0..50 {
assert!(watch.get().is_empty());
}
assert!(t.elapsed() < SLOW / 2, "get() waited for the scan: {:?}", t.elapsed());
// the scan is still held: a get() that waited for it could not have returned yet
assert_eq!(finished.load(Ordering::SeqCst), 0, "get() waited for the scan");
// nor may each call cost a fixed delay of its own: devices() runs every frame in menus
let bound = lightcraft_testkit::scaled(Duration::from_secs(1)).max(Duration::from_secs(1));
assert!(t.elapsed() < bound, "50 cold get() calls took {:?} (limit {bound:?})", t.elapsed());
assert!(watch.refreshing());
gate.store(true, Ordering::SeqCst);
assert!(until(|| !watch.refreshing()));
assert_eq!(runs.load(Ordering::SeqCst), 1, "requests while scanning are coalesced");
assert_eq!(changes.load(Ordering::SeqCst), 0, "nothing changed");
// a card is plugged in: the next stale request starts a rescan, still without waiting
gate.store(false, Ordering::SeqCst);
mounted.lock().unwrap().push(card("EOS_DIGITAL"));
std::thread::sleep(Duration::from_millis(40));
let t = std::time::Instant::now();
assert!(watch.get().is_empty(), "the old list is served while rescanning");
assert!(t.elapsed() < SLOW / 2, "warm get() waited: {:?}", t.elapsed());
assert!(t.elapsed() < bound, "the warm get() took {:?} (limit {bound:?})", t.elapsed());
assert_eq!(finished.load(Ordering::SeqCst), 1, "warm get() waited for the rescan");
gate.store(true, Ordering::SeqCst);
assert!(until(|| changes.load(Ordering::SeqCst) == 1), "a changed scan notifies");
assert_eq!(watch.get(), [card("EOS_DIGITAL")]);
// explicit requests scan synchronously
Expand Down
15 changes: 8 additions & 7 deletions crates/engine/src/tests/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn a_failing_download_ends_with_an_error_and_never_blocks() {
line.clear();
}
if let Some(released) = first.take() {
let _ = released.recv_timeout(Duration::from_secs(10));
let _ = released.recv_timeout(lightcraft_testkit::scaled(Duration::from_secs(30)).max(Duration::from_secs(30)));
}
let _ = c.write_all(b"HTTP/1.1 404 Not Found\r\nContent-Length: 13\r\nConnection: close\r\n\r\n<h1>404</h1>\n");
}
Expand All @@ -103,22 +103,23 @@ fn a_failing_download_ends_with_an_error_and_never_blocks() {
let mut s = Session::with_demo();
s.segmenter.dir = Some(dir.clone());
s.segmenter.mirrors_file = Some(mirrors.clone());
let t = Instant::now();
let r = s.execute("segment.model.download", &json!({"acknowledged": true})).unwrap();
assert_eq!(r["started"], true);
assert!(t.elapsed() < Duration::from_secs(1), "starting a download returns at once");
// the mirror holds its answer until `release`: still running means the call did not wait for it
assert!(s.segmenter.download_status().running, "starting a download returns at once");
// a second request while it runs starts nothing
let again = s.execute("segment.model.download", &json!({"acknowledged": true})).unwrap();
assert!(again["started"] == false || again["downloading"] == false);
// AI mask requests meanwhile: an error while the mirror still holds the download, never a wait for it
let e = s.execute("mask.add", &json!({"kind": "prompt", "text": "sky"})).unwrap_err().to_string();
assert!(e.contains(NOT_INSTALLED), "{e}");
assert!(s.segmenter.download_status().running, "the AI mask request did not wait for the download");
let _ = release.send(());
let t = Instant::now();
while s.segmenter.download_status().running {
assert!(t.elapsed() < Duration::from_secs(30), "the download never ended");
// AI mask requests meanwhile: an error at once, never a wait
let q = Instant::now();
assert!(t.elapsed() < lightcraft_testkit::scaled(Duration::from_secs(30)), "the download never ended");
let e = s.execute("mask.add", &json!({"kind": "prompt", "text": "sky"})).unwrap_err().to_string();
assert!(e.contains(NOT_INSTALLED), "{e}");
assert!(q.elapsed() < Duration::from_millis(500));
std::thread::sleep(Duration::from_millis(20));
}
let st = s.segmenter.download_status();
Expand Down
4 changes: 4 additions & 0 deletions crates/fetch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ rustls = { version = "0.23", default-features = false, features = ["std", "tls12
rustls-rustcrypto = "0.0.2-alpha"
webpki-roots = "1"
sha2 = { version = "0.10", default-features = false, features = ["std"] }

[dev-dependencies]
# deadlines stretched by LIGHTCRAFT_TIME_SCALE
lightcraft-testkit = { workspace = true }
Loading
Loading