From c1129ff6746b20b164b7bc6dadf851f396ef29ad Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 18 Dec 2020 11:53:43 +0100 Subject: [PATCH] Tests: Reset all cachex caches between synchronous tests Don't bother in the async case, it doesn't make sense there. --- test/support/conn_case.ex | 3 +-- test/support/data_case.ex | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 47cb65a80..b5bd71809 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -116,12 +116,11 @@ defmodule Pleroma.Web.ConnCase do end setup tags do - Cachex.clear(:user_cache) - Cachex.clear(:object_cache) :ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo) unless tags[:async] do Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()}) + Pleroma.DataCase.clear_cachex() end if tags[:needs_streamer] do diff --git a/test/support/data_case.ex b/test/support/data_case.ex index d5456521c..1f1d40863 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -45,13 +45,29 @@ defmodule Pleroma.DataCase do end end + def clear_cachex do + Pleroma.Supervisor + |> Supervisor.which_children() + |> Enum.each(fn + {name, _, _, [Cachex]} -> + name + |> to_string + |> String.trim_leading("cachex_") + |> Kernel.<>("_cache") + |> String.to_existing_atom() + |> Cachex.clear() + + _ -> + nil + end) + end + setup tags do - Cachex.clear(:user_cache) - Cachex.clear(:object_cache) :ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo) unless tags[:async] do Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()}) + clear_cachex() end if tags[:needs_streamer] do -- 2.45.2