diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/http/adapter_helper/gun_test.exs | 91 | ||||
-rw-r--r-- | test/pool/connections_test.exs | 617 |
2 files changed, 355 insertions, 353 deletions
diff --git a/test/http/adapter_helper/gun_test.exs b/test/http/adapter_helper/gun_test.exs index 2e961826e..95a8cf814 100644 --- a/test/http/adapter_helper/gun_test.exs +++ b/test/http/adapter_helper/gun_test.exs @@ -3,28 +3,27 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.HTTP.AdapterHelper.GunTest do - use ExUnit.Case, async: true + use ExUnit.Case use Pleroma.Tests.Helpers import Mox alias Pleroma.Config - alias Pleroma.Gun.Conn alias Pleroma.HTTP.AdapterHelper.Gun alias Pleroma.Pool.Connections setup :verify_on_exit! - - defp gun_mock(_) do - gun_mock() - :ok - end + setup :set_mox_global defp gun_mock do Pleroma.GunMock - |> stub(:open, fn _, _, _ -> Task.start_link(fn -> Process.sleep(1000) end) end) + |> stub(:open, fn _, _, _ -> + Task.start_link(fn -> Process.sleep(1000) end) + end) |> stub(:await_up, fn _, _ -> {:ok, :http} end) |> stub(:set_owner, fn _, _ -> :ok end) + + :ok end describe "options/1" do @@ -62,25 +61,6 @@ defmodule Pleroma.HTTP.AdapterHelper.GunTest do assert opts[:certificates_verification] end - test "get conn on next request" do - gun_mock() - level = Application.get_env(:logger, :level) - Logger.configure(level: :debug) - on_exit(fn -> Logger.configure(level: level) end) - uri = URI.parse("http://some-domain2.com") - - opts = Gun.options(uri) - - assert opts[:conn] == nil - assert opts[:close_conn] == nil - - Process.sleep(50) - opts = Gun.options(uri) - - assert is_pid(opts[:conn]) - assert opts[:close_conn] == false - end - test "merges with defaul http adapter config" do defaults = Gun.options([receive_conn: false], URI.parse("https://example.com")) assert Keyword.has_key?(defaults, :a) @@ -91,8 +71,6 @@ defmodule Pleroma.HTTP.AdapterHelper.GunTest do gun_mock() uri = URI.parse("https://some-domain.com") - :ok = Conn.open(uri, :gun_connections) - opts = Gun.options(uri) assert opts[:certificates_verification] @@ -134,11 +112,10 @@ defmodule Pleroma.HTTP.AdapterHelper.GunTest do end describe "options/1 with receive_conn parameter" do - setup :gun_mock + setup do: gun_mock() test "receive conn by default" do uri = URI.parse("http://another-domain.com") - :ok = Conn.open(uri, :gun_connections) received_opts = Gun.options(uri) assert received_opts[:close_conn] == false @@ -147,7 +124,6 @@ defmodule Pleroma.HTTP.AdapterHelper.GunTest do test "don't receive conn if receive_conn is false" do uri = URI.parse("http://another-domain.com") - :ok = Conn.open(uri, :gun_connections) opts = [receive_conn: false] received_opts = Gun.options(opts, uri) @@ -157,50 +133,51 @@ defmodule Pleroma.HTTP.AdapterHelper.GunTest do end describe "after_request/1" do - setup :gun_mock + setup do: gun_mock() test "body_as not chunks" do - uri = URI.parse("http://some-domain.com") - :ok = Conn.open(uri, :gun_connections) + uri = URI.parse("http://some-domain-5.com") opts = Gun.options(uri) :ok = Gun.after_request(opts) conn = opts[:conn] - assert %Connections{ - conns: %{ - "http:some-domain.com:80" => %Pleroma.Gun.Conn{ - conn: ^conn, - conn_state: :idle, - used_by: [] + assert match?( + %Connections{ + conns: %{ + "http:some-domain-5.com:80" => %Pleroma.Gun.Conn{ + conn: ^conn, + conn_state: :idle, + used_by: [] + } } - } - } = Connections.get_state(:gun_connections) + }, + Connections.get_state(:gun_connections) + ) end test "body_as chunks" do - uri = URI.parse("http://some-domain.com") - :ok = Conn.open(uri, :gun_connections) + uri = URI.parse("http://some-domain-6.com") opts = Gun.options([body_as: :chunks], uri) :ok = Gun.after_request(opts) conn = opts[:conn] self = self() - assert %Connections{ - conns: %{ - "http:some-domain.com:80" => %Pleroma.Gun.Conn{ - conn: ^conn, - conn_state: :active, - used_by: [{^self, _}] + assert match?( + %Connections{ + conns: %{ + "http:some-domain-6.com:80" => %Pleroma.Gun.Conn{ + conn: ^conn, + conn_state: :active, + used_by: [{^self, _}] + } } - } - } = Connections.get_state(:gun_connections) + }, + Connections.get_state(:gun_connections) + ) end test "with no connection" do uri = URI.parse("http://uniq-domain.com") - - :ok = Conn.open(uri, :gun_connections) - opts = Gun.options([body_as: :chunks], uri) conn = opts[:conn] opts = Keyword.delete(opts, :conn) @@ -221,7 +198,6 @@ defmodule Pleroma.HTTP.AdapterHelper.GunTest do test "with ipv4" do uri = URI.parse("http://127.0.0.1") - :ok = Conn.open(uri, :gun_connections) opts = Gun.options(uri) :ok = Gun.after_request(opts) conn = opts[:conn] @@ -239,7 +215,6 @@ defmodule Pleroma.HTTP.AdapterHelper.GunTest do test "with ipv6" do uri = URI.parse("http://[2a03:2880:f10c:83:face:b00c:0:25de]") - :ok = Conn.open(uri, :gun_connections) opts = Gun.options(uri) :ok = Gun.after_request(opts) conn = opts[:conn] diff --git a/test/pool/connections_test.exs b/test/pool/connections_test.exs index a7afb2190..ddc91fbb1 100644 --- a/test/pool/connections_test.exs +++ b/test/pool/connections_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Pool.ConnectionsTest do - use ExUnit.Case, async: true + use ExUnit.Case use Pleroma.Tests.Helpers import ExUnit.CaptureLog @@ -14,11 +14,19 @@ defmodule Pleroma.Pool.ConnectionsTest do alias Pleroma.Pool.Connections setup :verify_on_exit! + setup :set_mox_global setup_all do + {:ok, pid} = Agent.start_link(fn -> %{} end, name: :gun_state) + + on_exit(fn -> + if Process.alive?(pid), do: Agent.stop(pid) + end) + end + + setup do name = :test_connections - {:ok, pid} = Connections.start_link({name, [checkin_timeout: 150]}) - {:ok, _} = Registry.start_link(keys: :unique, name: Pleroma.GunMock) + {:ok, pid} = Connections.start_link({name, []}) on_exit(fn -> if Process.alive?(pid), do: GenServer.stop(name) @@ -53,28 +61,27 @@ defmodule Pleroma.Pool.ConnectionsTest do _ -> "http" end - Registry.register(GunMock, pid, %{ + info = %{ origin_scheme: scheme, origin_host: host, origin_port: port - }) + } + + Agent.update(:gun_state, &Map.put(&1, pid, %{info: info, ref: nil})) {:ok, pid} end - defp info(pid) do - [{_, info}] = Registry.lookup(GunMock, pid) - info - end + defp info(pid), do: Agent.get(:gun_state, & &1[pid][:info]) defp connect(pid, _) do ref = make_ref() - Registry.register(GunMock, ref, pid) + Agent.update(:gun_state, &put_in(&1[pid][:ref], ref)) ref end - defp await(pid, ref) do - [{_, ^pid}] = Registry.lookup(GunMock, ref) + defp await(pid, _ref) do + Agent.get(:gun_state, & &1[pid][:ref]) {:response, :fin, 200, []} end @@ -94,18 +101,6 @@ defmodule Pleroma.Pool.ConnectionsTest do open_mock() url = "http://some-domain.com" key = "http:some-domain.com:80" - refute Connections.checkin(url, name) - :ok = Conn.open(url, name) - - %Connections{ - conns: %{ - ^key => %Conn{ - gun_state: :up, - used_by: [], - conn_state: :idle - } - } - } = Connections.get_state(name) conn = Connections.checkin(url, name) assert is_pid(conn) @@ -113,65 +108,74 @@ defmodule Pleroma.Pool.ConnectionsTest do self = self() - %Connections{ - conns: %{ - ^key => %Conn{ - conn: ^conn, - gun_state: :up, - used_by: [{^self, _}], - conn_state: :active - } - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + ^key => %Conn{ + conn: ^conn, + gun_state: :up, + used_by: [{^self, _}], + conn_state: :active + } + } + }, + Connections.get_state(name) + ) reused_conn = Connections.checkin(url, name) assert conn == reused_conn - %Connections{ - conns: %{ - ^key => %Conn{ - conn: ^conn, - gun_state: :up, - used_by: [{^self, _}, {^self, _}], - conn_state: :active - } - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + ^key => %Conn{ + conn: ^conn, + gun_state: :up, + used_by: [{^self, _}, {^self, _}], + conn_state: :active + } + } + }, + Connections.get_state(name) + ) :ok = Connections.checkout(conn, self, name) - %Connections{ - conns: %{ - ^key => %Conn{ - conn: ^conn, - gun_state: :up, - used_by: [{^self, _}], - conn_state: :active - } - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + ^key => %Conn{ + conn: ^conn, + gun_state: :up, + used_by: [{^self, _}], + conn_state: :active + } + } + }, + Connections.get_state(name) + ) :ok = Connections.checkout(conn, self, name) - %Connections{ - conns: %{ - ^key => %Conn{ - conn: ^conn, - gun_state: :up, - used_by: [], - conn_state: :idle - } - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + ^key => %Conn{ + conn: ^conn, + gun_state: :up, + used_by: [], + conn_state: :idle + } + } + }, + Connections.get_state(name) + ) end test "reuse connection for idna domains", %{name: name} do open_mock() url = "http://ですsome-domain.com" - refute Connections.checkin(url, name) - - :ok = Conn.open(url, name) conn = Connections.checkin(url, name) assert is_pid(conn) @@ -179,16 +183,19 @@ defmodule Pleroma.Pool.ConnectionsTest do self = self() - %Connections{ - conns: %{ - "http:ですsome-domain.com:80" => %Conn{ - conn: ^conn, - gun_state: :up, - used_by: [{^self, _}], - conn_state: :active - } - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + "http:ですsome-domain.com:80" => %Conn{ + conn: ^conn, + gun_state: :up, + used_by: [{^self, _}], + conn_state: :active + } + } + }, + Connections.get_state(name) + ) reused_conn = Connections.checkin(url, name) @@ -199,26 +206,25 @@ defmodule Pleroma.Pool.ConnectionsTest do open_mock() url = "http://127.0.0.1" - refute Connections.checkin(url, name) - - :ok = Conn.open(url, name) - conn = Connections.checkin(url, name) assert is_pid(conn) assert Process.alive?(conn) self = self() - %Connections{ - conns: %{ - "http:127.0.0.1:80" => %Conn{ - conn: ^conn, - gun_state: :up, - used_by: [{^self, _}], - conn_state: :active - } - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + "http:127.0.0.1:80" => %Conn{ + conn: ^conn, + gun_state: :up, + used_by: [{^self, _}], + conn_state: :active + } + } + }, + Connections.get_state(name) + ) reused_conn = Connections.checkin(url, name) @@ -227,42 +233,44 @@ defmodule Pleroma.Pool.ConnectionsTest do :ok = Connections.checkout(conn, self, name) :ok = Connections.checkout(reused_conn, self, name) - %Connections{ - conns: %{ - "http:127.0.0.1:80" => %Conn{ - conn: ^conn, - gun_state: :up, - used_by: [], - conn_state: :idle - } - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + "http:127.0.0.1:80" => %Conn{ + conn: ^conn, + gun_state: :up, + used_by: [], + conn_state: :idle + } + } + }, + Connections.get_state(name) + ) end test "reuse for ipv6", %{name: name} do open_mock() url = "http://[2a03:2880:f10c:83:face:b00c:0:25de]" - refute Connections.checkin(url, name) - - :ok = Conn.open(url, name) - conn = Connections.checkin(url, name) assert is_pid(conn) assert Process.alive?(conn) self = self() - %Connections{ - conns: %{ - "http:2a03:2880:f10c:83:face:b00c:0:25de:80" => %Conn{ - conn: ^conn, - gun_state: :up, - used_by: [{^self, _}], - conn_state: :active - } - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + "http:2a03:2880:f10c:83:face:b00c:0:25de:80" => %Conn{ + conn: ^conn, + gun_state: :up, + used_by: [{^self, _}], + conn_state: :active + } + } + }, + Connections.get_state(name) + ) reused_conn = Connections.checkin(url, name) @@ -276,21 +284,23 @@ defmodule Pleroma.Pool.ConnectionsTest do self = self() url = "http://127.0.0.1" - :ok = Conn.open(url, name) conn = Connections.checkin(url, name) send(name, {:gun_down, conn, nil, nil, nil}) send(name, {:gun_up, conn, nil}) - %Connections{ - conns: %{ - "http:127.0.0.1:80" => %Conn{ - conn: ^conn, - gun_state: :up, - used_by: [{^self, _}], - conn_state: :active - } - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + "http:127.0.0.1:80" => %Conn{ + conn: ^conn, + gun_state: :up, + used_by: [{^self, _}], + conn_state: :active + } + } + }, + Connections.get_state(name) + ) end test "up and down ipv6", %{name: name} do @@ -301,21 +311,23 @@ defmodule Pleroma.Pool.ConnectionsTest do |> allow(self, name) url = "http://[2a03:2880:f10c:83:face:b00c:0:25de]" - :ok = Conn.open(url, name) conn = Connections.checkin(url, name) send(name, {:gun_down, conn, nil, nil, nil}) send(name, {:gun_up, conn, nil}) - %Connections{ - conns: %{ - "http:2a03:2880:f10c:83:face:b00c:0:25de:80" => %Conn{ - conn: ^conn, - gun_state: :up, - used_by: [{^self, _}], - conn_state: :active - } - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + "http:2a03:2880:f10c:83:face:b00c:0:25de:80" => %Conn{ + conn: ^conn, + gun_state: :up, + used_by: [{^self, _}], + conn_state: :active + } + } + }, + Connections.get_state(name) + ) end test "reuses connection based on protocol", %{name: name} do @@ -325,14 +337,10 @@ defmodule Pleroma.Pool.ConnectionsTest do https_url = "https://some-domain.com" https_key = "https:some-domain.com:443" - refute Connections.checkin(http_url, name) - :ok = Conn.open(http_url, name) conn = Connections.checkin(http_url, name) assert is_pid(conn) assert Process.alive?(conn) - refute Connections.checkin(https_url, name) - :ok = Conn.open(https_url, name) https_conn = Connections.checkin(https_url, name) refute conn == https_conn @@ -343,18 +351,21 @@ defmodule Pleroma.Pool.ConnectionsTest do assert reused_https == https_conn - %Connections{ - conns: %{ - ^http_key => %Conn{ - conn: ^conn, - gun_state: :up - }, - ^https_key => %Conn{ - conn: ^https_conn, - gun_state: :up - } - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + ^http_key => %Conn{ + conn: ^conn, + gun_state: :up + }, + ^https_key => %Conn{ + conn: ^https_conn, + gun_state: :up + } + } + }, + Connections.get_state(name) + ) end test "connection can't get up", %{name: name} do @@ -362,7 +373,6 @@ defmodule Pleroma.Pool.ConnectionsTest do url = "http://gun-not-up.com" assert capture_log(fn -> - refute Conn.open(url, name) refute Connections.checkin(url, name) end) =~ "Opening connection to http://gun-not-up.com failed with error {:error, :timeout}" @@ -377,33 +387,38 @@ defmodule Pleroma.Pool.ConnectionsTest do url = "http://gun-down-and-up.com" key = "http:gun-down-and-up.com:80" - :ok = Conn.open(url, name) conn = Connections.checkin(url, name) assert is_pid(conn) assert Process.alive?(conn) - %Connections{ - conns: %{ - ^key => %Conn{ - conn: ^conn, - gun_state: :up, - used_by: [{^self, _}] - } - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + ^key => %Conn{ + conn: ^conn, + gun_state: :up, + used_by: [{^self, _}] + } + } + }, + Connections.get_state(name) + ) send(name, {:gun_down, conn, :http, nil, nil}) - %Connections{ - conns: %{ - ^key => %Conn{ - conn: ^conn, - gun_state: :down, - used_by: [{^self, _}] - } - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + ^key => %Conn{ + conn: ^conn, + gun_state: :down, + used_by: [{^self, _}] + } + } + }, + Connections.get_state(name) + ) send(name, {:gun_up, conn, :http}) @@ -413,21 +428,23 @@ defmodule Pleroma.Pool.ConnectionsTest do assert is_pid(conn2) assert Process.alive?(conn2) - %Connections{ - conns: %{ - ^key => %Conn{ - conn: _, - gun_state: :up, - used_by: [{^self, _}, {^self, _}] - } - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + ^key => %Conn{ + conn: _, + gun_state: :up, + used_by: [{^self, _}, {^self, _}] + } + } + }, + Connections.get_state(name) + ) end test "async processes get same conn for same domain", %{name: name} do open_mock() url = "http://some-domain.com" - :ok = Conn.open(url, name) tasks = for _ <- 1..5 do @@ -445,15 +462,8 @@ defmodule Pleroma.Pool.ConnectionsTest do conns = for {:ok, value} <- results, do: value - %Connections{ - conns: %{ - "http:some-domain.com:80" => %Conn{ - conn: conn, - gun_state: :up - } - } - } = Connections.get_state(name) - + state = Connections.get_state(name) + %{conn: conn} = Map.get(state.conns, "http:some-domain.com:80") assert Enum.all?(conns, fn res -> res == conn end) end @@ -462,8 +472,6 @@ defmodule Pleroma.Pool.ConnectionsTest do self = self() http_url = "http://some-domain.com" https_url = "https://some-domain.com" - :ok = Conn.open(https_url, name) - :ok = Conn.open(http_url, name) conn1 = Connections.checkin(https_url, name) @@ -474,41 +482,44 @@ defmodule Pleroma.Pool.ConnectionsTest do http_key = "http:some-domain.com:80" - %Connections{ - conns: %{ - ^http_key => %Conn{ - conn: ^conn2, - gun_state: :up, - conn_state: :active, - used_by: [{^self, _}, {^self, _}, {^self, _}, {^self, _}] - }, - "https:some-domain.com:443" => %Conn{ - conn: ^conn1, - gun_state: :up, - conn_state: :active, - used_by: [{^self, _}] - } - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + ^http_key => %Conn{ + conn: ^conn2, + gun_state: :up, + conn_state: :active + }, + "https:some-domain.com:443" => %Conn{ + conn: ^conn1, + gun_state: :up, + conn_state: :active + } + } + }, + Connections.get_state(name) + ) :ok = Connections.checkout(conn1, self, name) another_url = "http://another-domain.com" - :ok = Conn.open(another_url, name) conn = Connections.checkin(another_url, name) - %Connections{ - conns: %{ - "http:another-domain.com:80" => %Conn{ - conn: ^conn, - gun_state: :up - }, - ^http_key => %Conn{ - conn: _, - gun_state: :up - } - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + "http:another-domain.com:80" => %Conn{ + conn: ^conn, + gun_state: :up + }, + ^http_key => %Conn{ + conn: _, + gun_state: :up + } + } + }, + Connections.get_state(name) + ) end describe "with proxy" do @@ -518,18 +529,19 @@ defmodule Pleroma.Pool.ConnectionsTest do url = "http://proxy-string.com" key = "http:proxy-string.com:80" - :ok = Conn.open(url, name, proxy: {{127, 0, 0, 1}, 8123}) - - conn = Connections.checkin(url, name) - - %Connections{ - conns: %{ - ^key => %Conn{ - conn: ^conn, - gun_state: :up - } - } - } = Connections.get_state(name) + conn = Connections.checkin(url, name, proxy: {{127, 0, 0, 1}, 8123}) + + assert match?( + %Connections{ + conns: %{ + ^key => %Conn{ + conn: ^conn, + gun_state: :up + } + } + }, + Connections.get_state(name) + ) reused_conn = Connections.checkin(url, name) @@ -541,17 +553,19 @@ defmodule Pleroma.Pool.ConnectionsTest do |> connect_mock() url = "http://proxy-tuple-atom.com" - :ok = Conn.open(url, name, proxy: {'localhost', 9050}) - conn = Connections.checkin(url, name) - - %Connections{ - conns: %{ - "http:proxy-tuple-atom.com:80" => %Conn{ - conn: ^conn, - gun_state: :up - } - } - } = Connections.get_state(name) + conn = Connections.checkin(url, name, proxy: {'localhost', 9050}) + + assert match?( + %Connections{ + conns: %{ + "http:proxy-tuple-atom.com:80" => %Conn{ + conn: ^conn, + gun_state: :up + } + } + }, + Connections.get_state(name) + ) reused_conn = Connections.checkin(url, name) @@ -564,17 +578,19 @@ defmodule Pleroma.Pool.ConnectionsTest do url = "https://proxy-string.com" - :ok = Conn.open(url, name, proxy: {{127, 0, 0, 1}, 8123}) - conn = Connections.checkin(url, name) + conn = Connections.checkin(url, name, proxy: {{127, 0, 0, 1}, 8123}) - %Connections{ - conns: %{ - "https:proxy-string.com:443" => %Conn{ - conn: ^conn, - gun_state: :up - } - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + "https:proxy-string.com:443" => %Conn{ + conn: ^conn, + gun_state: :up + } + } + }, + Connections.get_state(name) + ) reused_conn = Connections.checkin(url, name) @@ -586,17 +602,19 @@ defmodule Pleroma.Pool.ConnectionsTest do |> connect_mock() url = "https://proxy-tuple-atom.com" - :ok = Conn.open(url, name, proxy: {'localhost', 9050}) - conn = Connections.checkin(url, name) - - %Connections{ - conns: %{ - "https:proxy-tuple-atom.com:443" => %Conn{ - conn: ^conn, - gun_state: :up - } - } - } = Connections.get_state(name) + conn = Connections.checkin(url, name, proxy: {'localhost', 9050}) + + assert match?( + %Connections{ + conns: %{ + "https:proxy-tuple-atom.com:443" => %Conn{ + conn: ^conn, + gun_state: :up + } + } + }, + Connections.get_state(name) + ) reused_conn = Connections.checkin(url, name) @@ -608,18 +626,19 @@ defmodule Pleroma.Pool.ConnectionsTest do url = "http://proxy-socks.com" - :ok = Conn.open(url, name, proxy: {:socks5, 'localhost', 1234}) - - conn = Connections.checkin(url, name) + conn = Connections.checkin(url, name, proxy: {:socks5, 'localhost', 1234}) - %Connections{ - conns: %{ - "http:proxy-socks.com:80" => %Conn{ - conn: ^conn, - gun_state: :up - } - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + "http:proxy-socks.com:80" => %Conn{ + conn: ^conn, + gun_state: :up + } + } + }, + Connections.get_state(name) + ) reused_conn = Connections.checkin(url, name) @@ -630,18 +649,19 @@ defmodule Pleroma.Pool.ConnectionsTest do open_mock() url = "https://proxy-socks.com" - :ok = Conn.open(url, name, proxy: {:socks4, 'localhost', 1234}) - - conn = Connections.checkin(url, name) + conn = Connections.checkin(url, name, proxy: {:socks4, 'localhost', 1234}) - %Connections{ - conns: %{ - "https:proxy-socks.com:443" => %Conn{ - conn: ^conn, - gun_state: :up - } - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + "https:proxy-socks.com:443" => %Conn{ + conn: ^conn, + gun_state: :up + } + } + }, + Connections.get_state(name) + ) reused_conn = Connections.checkin(url, name) @@ -697,6 +717,10 @@ defmodule Pleroma.Pool.ConnectionsTest do end describe "get_unused_conns/1" do + setup %{name: name} do + Connections.refresh(name) + end + test "crf is equalent, sorting by reference", %{name: name} do Connections.add_conn(name, "1", %Conn{ conn_state: :idle, @@ -794,11 +818,14 @@ defmodule Pleroma.Pool.ConnectionsTest do |> Process.whereis() |> send({:close_idle_conns, 15}) - assert %Connections{ - conns: %{ - "3" => %Conn{}, - "2" => %Conn{} - } - } = Connections.get_state(name) + assert match?( + %Connections{ + conns: %{ + "3" => %Conn{}, + "2" => %Conn{} + } + }, + Connections.get_state(name) + ) end end |