From acbec2de68598fd64179387158d4c808220241cf Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Fri, 20 Mar 2026 00:10:22 +0100 Subject: Consolidate action map locks and fix immediate query visibility Replace three separate RwLocks (m_PendingLock, m_RunningLock, m_ResultsLock) with a single m_ActionMapLock guarding all three action maps. This eliminates lock-ordering requirements and prevents actions from being temporarily absent from all maps during state transitions. Additionally, insert actions into m_PendingActions immediately during EnqueueResolvedAction so they are visible to GetActionResult and FindActionResult right away, without waiting for the scheduler thread to process the update. Previously, eager clients could get a spurious 404 if they queried before the scheduler's HandleActionUpdates ran. Also adds debug logging for worker manifest, process launch and exit on Windows, and ANSI color helper macros for log formatting. --- src/zenserver-test/compute-tests.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/zenserver-test') diff --git a/src/zenserver-test/compute-tests.cpp b/src/zenserver-test/compute-tests.cpp index d088c2bee..e522ed203 100644 --- a/src/zenserver-test/compute-tests.cpp +++ b/src/zenserver-test/compute-tests.cpp @@ -2542,6 +2542,41 @@ TEST_CASE("function.retract_http") fmt::format("Second retract failed: status={}, body={}", int(RetractResp2.StatusCode), RetractResp2.ToText())); } +TEST_CASE("function.session.immediate_query_after_enqueue") +{ + // Verify that actions are immediately visible to GetActionResult and + // FindActionResult right after enqueue, without waiting for the + // scheduler thread to process the update. + + InMemoryChunkResolver Resolver; + ScopedTemporaryDirectory SessionBaseDir; + zen::compute::ComputeServiceSession Session(Resolver); + Session.Ready(); + + CbPackage WorkerPackage = BuildWorkerPackage(TestEnv, Resolver); + Session.RegisterWorker(WorkerPackage); + + CbObject ActionObj = BuildRot13ActionForSession("immediate-query"sv, Resolver); + + auto EnqueueRes = Session.EnqueueAction(ActionObj, 0); + REQUIRE_MESSAGE(EnqueueRes, "Failed to enqueue action"); + + // Query by LSN immediately — must not return NotFound + CbPackage Result; + HttpResponseCode Code = Session.GetActionResult(EnqueueRes.Lsn, Result); + CHECK_MESSAGE(Code == HttpResponseCode::Accepted, + fmt::format("GetActionResult returned {} immediately after enqueue, expected Accepted", int(Code))); + + // Query by ActionId immediately — must not return NotFound + const IoHash ActionId = ActionObj.GetHash(); + CbPackage FindResult; + HttpResponseCode FindCode = Session.FindActionResult(ActionId, FindResult); + CHECK_MESSAGE(FindCode == HttpResponseCode::Accepted, + fmt::format("FindActionResult returned {} immediately after enqueue, expected Accepted", int(FindCode))); + + Session.Shutdown(); +} + TEST_SUITE_END(); } // namespace zen::tests::compute -- cgit v1.2.3