1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.JobQueueMonitorTest do
6 use ExUnit.Case, async: true
8 alias Pleroma.JobQueueMonitor
10 @success {:process_event, :success, 1337,
12 args: %{"op" => "refresh_subscriptions"},
16 queue: "federator_outgoing",
17 worker: "Pleroma.Workers.SubscriberWorker"
20 @failure {:process_event, :failure, 22_521_134,
22 args: %{"op" => "force_password_reset", "user_id" => "9nJG6n6Nbu7tj9GJX6"},
24 error: %RuntimeError{message: "oops"},
30 {Pleroma.Workers.BackgroundWorker, :perform, 2,
31 [file: 'lib/pleroma/workers/background_worker.ex', line: 31]},
32 {Oban.Queue.Executor, :safe_call, 1,
33 [file: 'lib/oban/queue/executor.ex', line: 42]},
34 {:timer, :tc, 3, [file: 'timer.erl', line: 197]},
35 {Oban.Queue.Executor, :call, 2, [file: 'lib/oban/queue/executor.ex', line: 23]},
36 {Task.Supervised, :invoke_mfa, 2, [file: 'lib/task/supervised.ex', line: 90]},
37 {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}
39 worker: "Pleroma.Workers.BackgroundWorker"
43 assert %{processed_jobs: _, queues: _, workers: _} = JobQueueMonitor.stats()
46 test "handle_cast/2" do
47 state = %{workers: %{}, queues: %{}, processed_jobs: 0}
49 assert {:noreply, state} = JobQueueMonitor.handle_cast(@success, state)
50 assert {:noreply, state} = JobQueueMonitor.handle_cast(@failure, state)
51 assert {:noreply, state} = JobQueueMonitor.handle_cast(@success, state)
52 assert {:noreply, state} = JobQueueMonitor.handle_cast(@failure, state)
57 "background" => %{failure: 2, processed_jobs: 2, success: 0},
58 "federator_outgoing" => %{failure: 0, processed_jobs: 2, success: 2}
61 "Pleroma.Workers.BackgroundWorker" => %{
62 "force_password_reset" => %{failure: 2, processed_jobs: 2, success: 0}
64 "Pleroma.Workers.SubscriberWorker" => %{
65 "refresh_subscriptions" => %{failure: 0, processed_jobs: 2, success: 2}