diff options
| author | Roman Chvanikov <chvanikoff@pm.me> | 2020-09-20 19:27:27 +0300 |
|---|---|---|
| committer | Roman Chvanikov <chvanikoff@pm.me> | 2020-09-20 19:27:27 +0300 |
| commit | 4987ee6256c4227793240c74043845a661e3d37b (patch) | |
| tree | 40abf0e0c85df9788b59f24ed4026ae00a89e5e5 /test/web/fed_sockets/fetch_registry_test.exs | |
| parent | 44e8b6037ae71881327451dcf7d9351f1ba82674 (diff) | |
| parent | 882c1fc6bdff4e27955730a412d73ead0e67a741 (diff) | |
| download | pleroma-4987ee6256c4227793240c74043845a661e3d37b.tar.gz pleroma-4987ee6256c4227793240c74043845a661e3d37b.zip | |
Merge branch 'develop' into feature/expire-mutes
Diffstat (limited to 'test/web/fed_sockets/fetch_registry_test.exs')
| -rw-r--r-- | test/web/fed_sockets/fetch_registry_test.exs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/test/web/fed_sockets/fetch_registry_test.exs b/test/web/fed_sockets/fetch_registry_test.exs new file mode 100644 index 000000000..7bd2d995a --- /dev/null +++ b/test/web/fed_sockets/fetch_registry_test.exs @@ -0,0 +1,67 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.FedSockets.FetchRegistryTest do + use ExUnit.Case + + alias Pleroma.Web.FedSockets.FetchRegistry + alias Pleroma.Web.FedSockets.FetchRegistry.FetchRegistryData + + @json_message "hello" + @json_reply "hello back" + + setup do + start_supervised( + {Pleroma.Web.FedSockets.Supervisor, + [ + ping_interval: 8, + connection_duration: 15, + rejection_duration: 5, + fed_socket_fetches: [default: 10, interval: 10] + ]} + ) + + :ok + end + + test "fetches can be stored" do + uuid = FetchRegistry.register_fetch(@json_message) + + assert {:error, :waiting} = FetchRegistry.check_fetch(uuid) + end + + test "fetches can return" do + uuid = FetchRegistry.register_fetch(@json_message) + task = Task.async(fn -> FetchRegistry.register_fetch_received(uuid, @json_reply) end) + + assert {:error, :waiting} = FetchRegistry.check_fetch(uuid) + Task.await(task) + + assert {:ok, %FetchRegistryData{received_json: received_json}} = + FetchRegistry.check_fetch(uuid) + + assert received_json == @json_reply + end + + test "fetches are deleted once popped from stack" do + uuid = FetchRegistry.register_fetch(@json_message) + task = Task.async(fn -> FetchRegistry.register_fetch_received(uuid, @json_reply) end) + Task.await(task) + + assert {:ok, %FetchRegistryData{received_json: received_json}} = + FetchRegistry.check_fetch(uuid) + + assert received_json == @json_reply + assert {:ok, @json_reply} = FetchRegistry.pop_fetch(uuid) + + assert {:error, :missing} = FetchRegistry.check_fetch(uuid) + end + + test "fetches can time out" do + uuid = FetchRegistry.register_fetch(@json_message) + assert {:error, :waiting} = FetchRegistry.check_fetch(uuid) + Process.sleep(500) + assert {:error, :missing} = FetchRegistry.check_fetch(uuid) + end +end |
