Tests: Reset all cachex caches between synchronous tests
authorlain <lain@soykaf.club>
Fri, 18 Dec 2020 10:53:43 +0000 (11:53 +0100)
committerlain <lain@soykaf.club>
Fri, 18 Dec 2020 10:53:43 +0000 (11:53 +0100)
Don't bother in the async case, it doesn't make sense there.

test/support/conn_case.ex
test/support/data_case.ex

index 47cb65a80ba102febe685a2226c0f4153031be24..b5bd71809a195089fc1fbc098721154d83733346 100644 (file)
@@ -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
index d5456521c5296aabe641dabe8b778f324b5f42ec..1f1d40863655d6bcd950547487ddc70b6471c49e 100644 (file)
@@ -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