From 23301003717a5e154f54c14a5b8cb10ea2033e1a Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 19:10:57 -0500 Subject: [PATCH] Use config to control starting all HTTP pools in test env --- config/test.exs | 3 ++- lib/pleroma/application.ex | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/config/test.exs b/config/test.exs index afdb71d1d..28d0364c6 100644 --- a/config/test.exs +++ b/config/test.exs @@ -167,7 +167,8 @@ internal_fetch: false, load_custom_modules: false, max_restarts: 100, - streamer_registry: false + streamer_registry: false, + test_http_pools: true if File.exists?("./config/test.secret.exs") do import_config "test.secret.exs" diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 272529972..c0bfb898d 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -14,7 +14,6 @@ defmodule Pleroma.Application do @name Mix.Project.config()[:name] @version Mix.Project.config()[:version] @repository Mix.Project.config()[:source_url] - @mix_env Mix.env() def name, do: @name def version, do: @version @@ -98,7 +97,7 @@ def start(_type, _args) do {Task.Supervisor, name: Pleroma.TaskSupervisor} ] ++ cachex_children() ++ - http_children(adapter, @mix_env) ++ + http_children(adapter) ++ [ Pleroma.Stats, Pleroma.JobQueueMonitor, @@ -268,11 +267,19 @@ defp task_children() do end # start hackney and gun pools in tests - defp http_children(_, :test) do - http_children(Tesla.Adapter.Hackney, nil) ++ http_children(Tesla.Adapter.Gun, nil) + defp http_children(adapter) do + if Application.get_env(:pleroma, __MODULE__)[:test_http_pools] do + http_children_hackney() ++ http_children_gun() + else + cond do + match?(Tesla.Adapter.Hackney, adapter) -> http_children_hackney() + match?(Tesla.Adapter.Gun, adapter) -> http_children_gun() + true -> [] + end + end end - defp http_children(Tesla.Adapter.Hackney, _) do + defp http_children_hackney() do pools = [:federation, :media] pools = @@ -288,13 +295,11 @@ defp http_children(Tesla.Adapter.Hackney, _) do end end - defp http_children(Tesla.Adapter.Gun, _) do + defp http_children_gun() do Pleroma.Gun.ConnectionPool.children() ++ [{Task, &Pleroma.HTTP.AdapterHelper.Gun.limiter_setup/0}] end - defp http_children(_, _), do: [] - @spec limiters_setup() :: :ok def limiters_setup do config = Config.get(ConcurrentLimiter, [])