From 4a23f400e9b505caafdbb6b009d03d49b2469da1 Mon Sep 17 00:00:00 2001 From: dajiaohuang Date: Fri, 18 Sep 2026 02:21:25 +0800 Subject: [PATCH] Fix update_job_state/3 in the Quantum.Storage.Test macro A storage defined with `use Quantum.Storage.Test` sent only the job name in its `update_job_state/3` notification and returned the new state to the caller. The `Quantum.Storage` callback returns `:ok` and `Quantum.JobBroadcaster` matches it as such, so activating or deactivating a job crashed the job broadcaster with a `MatchError` for every storage built with the macro. Send `{job_name, state}`, as the module-level implementation in the same file already does, and let the helper return its default `:ok`. Adds a regression test that deactivates a job on a storage built with the macro. --- test/quantum/job_broadcaster_test.exs | 15 +++++++++++++++ test/support/test_storage.ex | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/test/quantum/job_broadcaster_test.exs b/test/quantum/job_broadcaster_test.exs index 28e33b3..07595f2 100644 --- a/test/quantum/job_broadcaster_test.exs +++ b/test/quantum/job_broadcaster_test.exs @@ -456,6 +456,21 @@ defmodule Quantum.JobBroadcasterTest do assert_receive %{test_id: ^test_id} end + @tag jobs: :active, listen_storage: true, storage: :with_update + test "active => inactive with updating storage", %{ + broadcaster: broadcaster, + active_job: active_job + } do + active_job_name = active_job.name + + capture_log(fn -> + TestScheduler.deactivate_job(broadcaster, active_job_name) + + assert_receive {:received, {:remove, ^active_job_name}} + assert_receive {:update_job_state, {^active_job_name, :inactive}, _} + end) + end + @tag jobs: :inactive, listen_storage: true test "inactive => active", %{broadcaster: broadcaster, inactive_job: inactive_job} do test_id = "update-inactive-to-active-job-handler" diff --git a/test/support/test_storage.ex b/test/support/test_storage.ex index 6535991..9afd331 100644 --- a/test/support/test_storage.ex +++ b/test/support/test_storage.ex @@ -62,7 +62,7 @@ defmodule Quantum.Storage.Test do @impl Quantum.Storage def update_job_state(_storage_pid, job_name, state), - do: send_and_wait(:update_job_state, job_name, state) + do: send_and_wait(:update_job_state, {job_name, state}) @impl Quantum.Storage def last_execution_date(_storage_pid),