1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.User.BackupAsyncTest do
6 use Pleroma.DataCase, async: true
11 alias Pleroma.UnstubbedConfigMock, as: ConfigMock
12 alias Pleroma.User.Backup
13 alias Pleroma.User.Backup.ProcessorMock
16 user = insert(:user, %{nickname: "cofe", name: "Cofe", ap_id: "http://cofe.io/users/cofe"})
18 {:ok, backup} = user |> Backup.new() |> Repo.insert()
22 @tag capture_log: true
23 test "it handles unrecoverable exceptions", %{backup: backup} do
25 |> expect(:do_process, fn _, _ ->
26 raise "mock exception"
30 |> stub_with(Pleroma.Config)
32 {:error, %{backup: backup, reason: :exit}} = Backup.process(backup, ProcessorMock)
34 assert backup.state == :failed
37 @tag capture_log: true
38 test "it handles timeouts", %{backup: backup} do
40 |> expect(:do_process, fn _, _ ->
41 Process.sleep(:timer.seconds(4))
45 |> expect(:get, fn [Pleroma.User.Backup, :process_wait_time] -> :timer.seconds(2) end)
47 {:error, %{backup: backup, reason: :timeout}} = Backup.process(backup, ProcessorMock)
49 assert backup.state == :failed