Merge branch 'fix/search-test-on-exit' into 'develop'

Search tests: Use on_exit for restoring `persistent_term` state

See merge request pleroma/pleroma!3182
This commit is contained in:
rinpatch 2020-12-01 17:08:05 +00:00
commit 57d0379b89
2 changed files with 2 additions and 4 deletions

View File

@ -21,6 +21,7 @@ defmodule Pleroma.Activity.SearchTest do
test "using plainto_tsquery on postgres < 11" do test "using plainto_tsquery on postgres < 11" do
old_version = :persistent_term.get({Pleroma.Repo, :postgres_version}) old_version = :persistent_term.get({Pleroma.Repo, :postgres_version})
:persistent_term.put({Pleroma.Repo, :postgres_version}, 10.0) :persistent_term.put({Pleroma.Repo, :postgres_version}, 10.0)
on_exit(fn -> :persistent_term.put({Pleroma.Repo, :postgres_version}, old_version) end)
user = insert(:user) user = insert(:user)
{:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"}) {:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
@ -30,8 +31,6 @@ defmodule Pleroma.Activity.SearchTest do
assert [result] = Search.search(nil, "wednesday -dudes") assert [result] = Search.search(nil, "wednesday -dudes")
assert result.id == post.id assert result.id == post.id
:persistent_term.put({Pleroma.Repo, :postgres_version}, old_version)
end end
test "using websearch_to_tsquery" do test "using websearch_to_tsquery" do

View File

@ -281,6 +281,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
test "search fetches remote statuses and prefers them over other results", %{conn: conn} do test "search fetches remote statuses and prefers them over other results", %{conn: conn} do
old_version = :persistent_term.get({Pleroma.Repo, :postgres_version}) old_version = :persistent_term.get({Pleroma.Repo, :postgres_version})
:persistent_term.put({Pleroma.Repo, :postgres_version}, 10.0) :persistent_term.put({Pleroma.Repo, :postgres_version}, 10.0)
on_exit(fn -> :persistent_term.put({Pleroma.Repo, :postgres_version}, old_version) end)
capture_log(fn -> capture_log(fn ->
{:ok, %{id: activity_id}} = {:ok, %{id: activity_id}} =
@ -298,8 +299,6 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
%{"id" => ^activity_id} %{"id" => ^activity_id}
] = results["statuses"] ] = results["statuses"]
end) end)
:persistent_term.put({Pleroma.Repo, :postgres_version}, old_version)
end end
test "search doesn't show statuses that it shouldn't", %{conn: conn} do test "search doesn't show statuses that it shouldn't", %{conn: conn} do