mirror of
https://github.com/storytold/effectcraft.git
synced 2026-10-31 23:58:21 +00:00
Footage watcher host test: wait for each wake before taking its stamps
The worker stores a report and then wakes the interface; the test took the report as soon as it was there and asserted the wake count right after, which can run before the wake. `next` now waits for the n-th wake and then takes the stamps, as the engine tests' `wait_for` does. Checked with 50 ms between the worker's report and its wake: this test passes; the previous one fails at `wakes == 1`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4c8b9cfc26
commit
99da7e2568
1 file changed
+8
-4
@@ -171,10 +171,14 @@ fn the_watcher_notices_a_footage_file_changed_on_disk() {
|
||||
.unwrap();
|
||||
w.set_focused(true);
|
||||
w.set_watched(footage_reload::watched(&s));
|
||||
let next = |w: &footage_reload::Watcher| {
|
||||
// Report `n`: the worker stores the stamps and then wakes the interface, so wait for the
|
||||
// wake too, not only for the stamps.
|
||||
let next = |w: &footage_reload::Watcher, n: usize| {
|
||||
let t0 = Instant::now();
|
||||
loop {
|
||||
if let Some(stamps) = w.take() {
|
||||
if wakes.load(Ordering::SeqCst) >= n
|
||||
&& let Some(stamps) = w.take()
|
||||
{
|
||||
return stamps;
|
||||
}
|
||||
assert!(t0.elapsed() < Duration::from_secs(10), "the watcher never reported");
|
||||
@@ -182,14 +186,14 @@ fn the_watcher_notices_a_footage_file_changed_on_disk() {
|
||||
}
|
||||
};
|
||||
// First look: remembered, nothing to reload.
|
||||
assert_eq!(footage_reload::apply_stamps(&mut s, next(&w)).unwrap(), json!({"files": 0, "reloaded": 0}));
|
||||
assert_eq!(footage_reload::apply_stamps(&mut s, next(&w, 1)).unwrap(), json!({"files": 0, "reloaded": 0}));
|
||||
assert_eq!(wakes.load(Ordering::SeqCst), 1);
|
||||
std::thread::sleep(fast * 15);
|
||||
assert!(w.take().is_none(), "an unchanged file is never reported");
|
||||
assert_eq!(wakes.load(Ordering::SeqCst), 1, "and never wakes the interface");
|
||||
// Saved in another app: reported once, reloaded, shown.
|
||||
save(&path, &flat(GREEN, true));
|
||||
assert_eq!(footage_reload::apply_stamps(&mut s, next(&w)).unwrap(), json!({"files": 1, "reloaded": 1}));
|
||||
assert_eq!(footage_reload::apply_stamps(&mut s, next(&w, 2)).unwrap(), json!({"files": 1, "reloaded": 1}));
|
||||
assert!(near(pixel(&s, cid, 32, 24), GREEN));
|
||||
assert_eq!(wakes.load(Ordering::SeqCst), 2);
|
||||
std::thread::sleep(fast * 10);
|
||||
|
||||
Reference in new issue
Block a user