logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

job_queue_monitor_test.exs (2792B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.JobQueueMonitorTest do
  5. use ExUnit.Case, async: true
  6. alias Pleroma.JobQueueMonitor
  7. @success {:process_event, :success, 1337,
  8. %{
  9. args: %{"op" => "refresh_subscriptions"},
  10. attempt: 1,
  11. id: 339,
  12. max_attempts: 5,
  13. queue: "federator_outgoing",
  14. worker: "Pleroma.Workers.SubscriberWorker"
  15. }}
  16. @failure {:process_event, :failure, 22_521_134,
  17. %{
  18. args: %{"op" => "force_password_reset", "user_id" => "9nJG6n6Nbu7tj9GJX6"},
  19. attempt: 1,
  20. error: %RuntimeError{message: "oops"},
  21. id: 345,
  22. kind: :exception,
  23. max_attempts: 1,
  24. queue: "background",
  25. stack: [
  26. {Pleroma.Workers.BackgroundWorker, :perform, 2,
  27. [file: 'lib/pleroma/workers/background_worker.ex', line: 31]},
  28. {Oban.Queue.Executor, :safe_call, 1,
  29. [file: 'lib/oban/queue/executor.ex', line: 42]},
  30. {:timer, :tc, 3, [file: 'timer.erl', line: 197]},
  31. {Oban.Queue.Executor, :call, 2, [file: 'lib/oban/queue/executor.ex', line: 23]},
  32. {Task.Supervised, :invoke_mfa, 2, [file: 'lib/task/supervised.ex', line: 90]},
  33. {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}
  34. ],
  35. worker: "Pleroma.Workers.BackgroundWorker"
  36. }}
  37. test "stats/0" do
  38. assert %{processed_jobs: _, queues: _, workers: _} = JobQueueMonitor.stats()
  39. end
  40. test "handle_cast/2" do
  41. state = %{workers: %{}, queues: %{}, processed_jobs: 0}
  42. assert {:noreply, state} = JobQueueMonitor.handle_cast(@success, state)
  43. assert {:noreply, state} = JobQueueMonitor.handle_cast(@failure, state)
  44. assert {:noreply, state} = JobQueueMonitor.handle_cast(@success, state)
  45. assert {:noreply, state} = JobQueueMonitor.handle_cast(@failure, state)
  46. assert state == %{
  47. processed_jobs: 4,
  48. queues: %{
  49. "background" => %{failure: 2, processed_jobs: 2, success: 0},
  50. "federator_outgoing" => %{failure: 0, processed_jobs: 2, success: 2}
  51. },
  52. workers: %{
  53. "Pleroma.Workers.BackgroundWorker" => %{
  54. "force_password_reset" => %{failure: 2, processed_jobs: 2, success: 0}
  55. },
  56. "Pleroma.Workers.SubscriberWorker" => %{
  57. "refresh_subscriptions" => %{failure: 0, processed_jobs: 2, success: 2}
  58. }
  59. }
  60. }
  61. end
  62. end