retry_queue_test.exs (1310B)
1 # Pleroma: A lightweight social networking server 2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> 3 # SPDX-License-Identifier: AGPL-3.0-only 4 5 defmodule MockActivityPub do 6 def publish_one({ret, waiter}) do 7 send(waiter, :complete) 8 {ret, "success"} 9 end 10 end 11 12 defmodule Pleroma.Web.Federator.RetryQueueTest do 13 use Pleroma.DataCase 14 alias Pleroma.Web.Federator.RetryQueue 15 16 @small_retry_count 0 17 @hopeless_retry_count 10 18 19 setup do 20 RetryQueue.reset_stats() 21 end 22 23 test "RetryQueue responds to stats request" do 24 assert %{delivered: 0, dropped: 0} == RetryQueue.get_stats() 25 end 26 27 test "failed posts are retried" do 28 {:retry, _timeout} = RetryQueue.get_retry_params(@small_retry_count) 29 30 wait_task = 31 Task.async(fn -> 32 receive do 33 :complete -> :ok 34 end 35 end) 36 37 RetryQueue.enqueue({:ok, wait_task.pid}, MockActivityPub, @small_retry_count) 38 Task.await(wait_task) 39 assert %{delivered: 1, dropped: 0} == RetryQueue.get_stats() 40 end 41 42 test "posts that have been tried too many times are dropped" do 43 {:drop, _timeout} = RetryQueue.get_retry_params(@hopeless_retry_count) 44 45 RetryQueue.enqueue({:ok, nil}, MockActivityPub, @hopeless_retry_count) 46 assert %{delivered: 0, dropped: 1} == RetryQueue.get_stats() 47 end 48 end