Tests: two Properties tests no longer fail at random on a busy machine (#11750)
* claim: Properties: hold the measuring worker in tests until the card is checked * Properties: hold the measuring worker in tests until the card is checked open_object starts the measurement on a worker and looks for the reply once without waiting. Under load the window side could be held up between the two, the reply was already in, and two Properties tests saw the card filled where it should still be measuring (about 0.3 % and 4 % of runs with 18 tests at a time). measure_beside now runs a hold before sending the reply. In tests it waits on the app's existing apply_gate, which feature evaluation already uses for the same purpose; outside tests it does nothing. Both tests set the gate, check the card is measuring, then let the worker go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6312c2760a
commit
9d7bbb7fa9
2 files changed
+28
-3
No files matched your search
@@ -133,8 +133,20 @@ pub fn open_object(app: &mut SolveApp, command: &str, params: &Value, fallback:
|
||||
// copy beside it, the card shows when done. Headless and in tests (no wait set), here.
|
||||
// The worker reports how many bodies it has measured, and stops when the card closes (#8706).
|
||||
let progress = Arc::new(Progress::default());
|
||||
// Tests hold the reply until let go (`apply_gate`), so a window thread held up under load
|
||||
// cannot find the measurement already in where the card should still be measuring.
|
||||
#[cfg(test)]
|
||||
let gate = app.apply_gate.clone();
|
||||
let hold = move || {
|
||||
#[cfg(test)]
|
||||
if let Some(gate) = gate
|
||||
&& let Ok(gate) = gate.lock()
|
||||
{
|
||||
let _ = gate.recv();
|
||||
}
|
||||
};
|
||||
if let Some(wait) = app.apply_off_thread
|
||||
&& let Some(rx) = measure_beside(app.session.scratch(), command, params, progress.clone())
|
||||
&& let Some(rx) = measure_beside(app.session.scratch(), command, params, progress.clone(), hold)
|
||||
{
|
||||
match rx.recv_timeout(wait) {
|
||||
Ok(reply) => opened(app, reply, fallback),
|
||||
@@ -190,13 +202,14 @@ fn opened(app: &mut SolveApp, reply: Result<Value, String>, fallback: String) {
|
||||
}
|
||||
|
||||
/// Run `command` on `copy` on a worker, watched by `progress`; the reply comes on the returned
|
||||
/// channel.
|
||||
/// channel once `hold` returns (which only tests make wait).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn measure_beside(
|
||||
mut copy: solidcraft_engine::Session,
|
||||
command: &str,
|
||||
params: &Value,
|
||||
progress: Arc<Progress>,
|
||||
hold: impl FnOnce() + Send + 'static,
|
||||
) -> Option<std::sync::mpsc::Receiver<Result<Value, String>>> {
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
let (command, params) = (command.to_string(), params.clone());
|
||||
@@ -204,6 +217,7 @@ fn measure_beside(
|
||||
.name("properties".into())
|
||||
.spawn(move || {
|
||||
let reply = solidcraft_engine::doc::progress::watch(progress, || copy.execute(&command, ¶ms));
|
||||
hold();
|
||||
let _ = tx.send(reply.map_err(|e| e.to_string()));
|
||||
})
|
||||
.ok()?;
|
||||
@@ -217,6 +231,7 @@ fn measure_beside(
|
||||
_command: &str,
|
||||
_params: &Value,
|
||||
_progress: Arc<Progress>,
|
||||
_hold: impl FnOnce() + Send + 'static,
|
||||
) -> Option<std::sync::mpsc::Receiver<Result<Value, String>>> {
|
||||
None
|
||||
}
|
||||
@@ -631,9 +646,14 @@ mod tests {
|
||||
h.app.run("solid.box", json!({"length": 10, "width": 20, "height": 30, "body_name": "Block"})).unwrap();
|
||||
let here = h.app.session.execute("component.properties", &json!({})).unwrap();
|
||||
h.app.apply_off_thread = Some(std::time::Duration::ZERO);
|
||||
// The worker holds its reply until let go, so a window thread held up under load cannot
|
||||
// find it already in.
|
||||
let (finish, gate) = std::sync::mpsc::channel();
|
||||
h.app.apply_gate = Some(std::sync::Arc::new(std::sync::Mutex::new(gate)));
|
||||
super::open_object(&mut h.app, "component.properties", &json!({}), String::new());
|
||||
assert!(h.app.menu.props.is_none(), "nothing is waited for on the window thread");
|
||||
let m = h.app.menu.props_measuring.take().expect("measuring beside the window");
|
||||
finish.send(()).unwrap();
|
||||
assert_eq!(m.rx.recv().unwrap().unwrap(), here, "the copy measures what the design here does");
|
||||
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
@@ -674,11 +694,15 @@ mod tests {
|
||||
h.app.run("occurrence.copy", json!({"component": block, "translate": [20 * i, 0, 0]})).unwrap();
|
||||
}
|
||||
h.app.apply_off_thread = Some(std::time::Duration::ZERO);
|
||||
// Held until checked: under load the worker could otherwise finish before the menu returns.
|
||||
let (finish, gate) = std::sync::mpsc::channel();
|
||||
h.app.apply_gate = Some(std::sync::Arc::new(std::sync::Mutex::new(gate)));
|
||||
let items = crate::context_menu::items(&h.app, &crate::context_menu::Target::Component { id: 0 });
|
||||
let item = items.iter().find(|i| i.label == "Properties").expect("Properties item");
|
||||
crate::context_menu::run_item(&mut h.app, item, egui::pos2(0.0, 0.0));
|
||||
assert!(h.app.menu.props_measuring.is_some(), "the menu returns at once, the card measuring");
|
||||
assert!(h.app.menu.props.is_none());
|
||||
finish.send(()).unwrap();
|
||||
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(300);
|
||||
while h.app.menu.props.is_none() {
|
||||
assert!(std::time::Instant::now() < deadline, "the measurements never came in");
|
||||
|
||||
@@ -619,7 +619,8 @@ pub struct SolveApp {
|
||||
/// How long OK waits for a feature before computing it off the window thread, saying so;
|
||||
/// `None`: it waits as long as it takes (headless use, tests). The desktop app sets it.
|
||||
pub apply_off_thread: Option<std::time::Duration>,
|
||||
/// Tests: the off-thread evaluation waits for this before it reports done.
|
||||
/// Tests: work started off the window thread (a feature's evaluation, a Properties
|
||||
/// measurement) waits for this before it reports done.
|
||||
#[cfg(test)]
|
||||
pub(crate) apply_gate: Option<std::sync::Arc<std::sync::Mutex<std::sync::mpsc::Receiver<()>>>>,
|
||||
/// The last command started interactively (id, label), for Repeat.
|
||||
|
||||
Reference in new issue
Block a user