From 6a055745ad03bc357805f3290581e179b0c2d2ca Mon Sep 17 00:00:00 2001 From: HanifKoh <76276251+HanifKoh@users.noreply.github.com> Date: Fri, 27 Nov 2026 22:45:08 +0800 Subject: [PATCH] Start the Person's Job Only After the Call's Change in the MCP Worker-Claim Test (#17952) The test slept 60 ms before starting the worker job and expected the call to have found the worker idle by then. On a loaded runner the call's thread could start later, so the job was already running, the call was refused as busy and its reply had no status. The test now waits until the call's change has run, and the call settles until the job starts, so the order holds on any machine. --- tests/slic3rutils/test_mcp_scene.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/slic3rutils/test_mcp_scene.cpp b/tests/slic3rutils/test_mcp_scene.cpp index 3c2e441541..c2ccda0d3c 100644 --- a/tests/slic3rutils/test_mcp_scene.cpp +++ b/tests/slic3rutils/test_mcp_scene.cpp @@ -67,6 +67,7 @@ #include #include #include +#include #include #include #include @@ -543,21 +544,25 @@ TEST_CASE("a worker job that starts between a call's closures is the call's, who { // The worker doesn't record who queued a job, so a person's job that starts while a call that // found the worker idle is still running is claimed by that call, as one its change queued is. - Harness h; - h.add("settle", GuardClass::Mutate, [](const json&, ToolContext& ctx) { + Harness h; + std::promise edited; + h.add("settle", GuardClass::Mutate, [&h, &edited](const json&, ToolContext& ctx) { ctx.run_ui([] { return json("edited"); }); - for (int i = 0; i < 10; ++i) { - ctx.observe_ui([] { return json(); }); + edited.set_value(); + // Settles until the job starts, so the closure that sees it busy is the one that claims it. + for (int i = 0; i < 250 && !ctx.observe_ui([&h] { return json(h.worker.busy()); }).get(); ++i) std::this_thread::sleep_for(20ms); - } return ToolResult::ok(); }); h.start(); - ToolResult settled; - std::thread caller([&h, &settled] { settled = h.call("settle"); }); - std::this_thread::sleep_for(60ms); - h.ui.post([&h] { h.worker.start(h.job_length); }); // a person starts Text typing + ToolResult settled; + std::thread caller([&h, &settled] { settled = h.call("settle"); }); + // Only once the call's change has run, which found the worker idle; a job started before it refuses the call. + const bool changed = edited.get_future().wait_for(5000ms) == std::future_status::ready; + if (changed) + h.ui.post([&h] { h.worker.start(h.job_length); }); // a person starts Text typing caller.join(); + REQUIRE(changed); REQUIRE(settled.data["status"] == "running"); const std::string job = settled.data["job"]; CHECK(h.refused_by(h.call("edit"), job));