Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky test #478

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions test/mindwendel/accounts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,14 @@ defmodule Mindwendel.AccountsTest do
Factory.insert!(:idea, brainstorming: old_brainstorming, user: old_user)

# we want to make sure that the database is not handling this with a foreign key restraint, but rather that it's handled in the app:
{_result, log} =
with_log(fn ->
Accounts.delete_inactive_users()
end)
log = capture_log(fn -> Accounts.delete_inactive_users() end)

assert Repo.exists?(from u in User, where: u.id == ^old_user.id)
assert log == ""

# The code only logs normal messages on `info` level which tests don't print (only warning and above)
# since we're run async we can't assert an empty log (picks up log messages from other tests as well),
# but we can assert we're not hitting the messages we know we'll throw.
refute log =~ ~r/error.*delete.*inactive.*user.*#{old_user.id}/i
end

test "does not delete the user a user is a creating user of a brainstorming", %{
Expand All @@ -107,13 +108,10 @@ defmodule Mindwendel.AccountsTest do
)

# we want to make sure that the database is not handling this with a foreign key restraint, but rather that it's handled in the app:
{_result, log} =
with_log(fn ->
Accounts.delete_inactive_users()
end)
log = capture_log(fn -> Accounts.delete_inactive_users() end)

assert Repo.exists?(from u in User, where: u.id == ^old_user.id)
assert log == ""
refute log =~ ~r/error.*delete.*inactive.*user.*#{old_user.id}/i
end

test "does not delete the user a user is a moderating user of a brainstorming", %{
Expand All @@ -125,16 +123,13 @@ defmodule Mindwendel.AccountsTest do
)

# we want to make sure that the database is not handling this with a foreign key restraint, but rather that it's handled in the app:
log =
capture_log(fn ->
Accounts.delete_inactive_users()
end)
log = capture_log(fn -> Accounts.delete_inactive_users() end)

assert Repo.exists?(from u in User, where: u.id == ^old_user.id)
# we don't expect actual logs but due to async running other tests may emit logs at
# the same time and so we want to make sure here that no delete logs around the user
# are emitted
refute log =~ ~r/delet.*#{old_user.id}/i
refute log =~ ~r/error.*delete.*inactive.*user.*#{old_user.id}/i
end
end
end