logo

pleroma

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

fetch_registry_test.exs (2005B)


  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.Web.FedSockets.FetchRegistryTest do
  5. use ExUnit.Case
  6. alias Pleroma.Web.FedSockets.FetchRegistry
  7. alias Pleroma.Web.FedSockets.FetchRegistry.FetchRegistryData
  8. @json_message "hello"
  9. @json_reply "hello back"
  10. setup do
  11. start_supervised(
  12. {Pleroma.Web.FedSockets.Supervisor,
  13. [
  14. ping_interval: 8,
  15. connection_duration: 15,
  16. rejection_duration: 5,
  17. fed_socket_fetches: [default: 10, interval: 10]
  18. ]}
  19. )
  20. :ok
  21. end
  22. test "fetches can be stored" do
  23. uuid = FetchRegistry.register_fetch(@json_message)
  24. assert {:error, :waiting} = FetchRegistry.check_fetch(uuid)
  25. end
  26. test "fetches can return" do
  27. uuid = FetchRegistry.register_fetch(@json_message)
  28. task = Task.async(fn -> FetchRegistry.register_fetch_received(uuid, @json_reply) end)
  29. assert {:error, :waiting} = FetchRegistry.check_fetch(uuid)
  30. Task.await(task)
  31. assert {:ok, %FetchRegistryData{received_json: received_json}} =
  32. FetchRegistry.check_fetch(uuid)
  33. assert received_json == @json_reply
  34. end
  35. test "fetches are deleted once popped from stack" do
  36. uuid = FetchRegistry.register_fetch(@json_message)
  37. task = Task.async(fn -> FetchRegistry.register_fetch_received(uuid, @json_reply) end)
  38. Task.await(task)
  39. assert {:ok, %FetchRegistryData{received_json: received_json}} =
  40. FetchRegistry.check_fetch(uuid)
  41. assert received_json == @json_reply
  42. assert {:ok, @json_reply} = FetchRegistry.pop_fetch(uuid)
  43. assert {:error, :missing} = FetchRegistry.check_fetch(uuid)
  44. end
  45. test "fetches can time out" do
  46. uuid = FetchRegistry.register_fetch(@json_message)
  47. assert {:error, :waiting} = FetchRegistry.check_fetch(uuid)
  48. Process.sleep(500)
  49. assert {:error, :missing} = FetchRegistry.check_fetch(uuid)
  50. end
  51. end