summaryrefslogtreecommitdiff
path: root/test/web/retry_queue_test.exs
blob: 9351b6c24bd14e5a7994feb443d48f7d4c86d029 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Pleroma: A lightweight social networking server
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule MockActivityPub do
  def publish_one(ret) do
    {ret, "success"}
  end
end

defmodule Pleroma.Web.Federator.RetryQueueTest do
  use Pleroma.DataCase
  alias Pleroma.Web.Federator.RetryQueue

  @small_retry_count 0
  @hopeless_retry_count 10

  test "failed posts are retried" do
    {:retry, _timeout} = RetryQueue.get_retry_params(@small_retry_count)

    assert {:noreply, %{delivered: 1}} ==
             RetryQueue.handle_info({:send, :ok, MockActivityPub, @small_retry_count}, %{
               delivered: 0
             })
  end

  test "posts that have been tried too many times are dropped" do
    {:drop, _timeout} = RetryQueue.get_retry_params(@hopeless_retry_count)

    assert {:noreply, %{dropped: 1}} ==
             RetryQueue.handle_cast({:maybe_enqueue, %{}, nil, @hopeless_retry_count}, %{
               dropped: 0
             })
  end
end