Skip to content

Commit

Permalink
Pass async to tests, parallelizing them (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
PragTob authored Nov 10, 2024
1 parent ca9cf8e commit 5213ae2
Show file tree
Hide file tree
Showing 31 changed files with 44 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.Nesting, []},
{Credo.Check.Refactor.PassAsyncInTestCases, []},
{Credo.Check.Refactor.RedundantWithClauseResult, []},
{Credo.Check.Refactor.RejectReject, []},
{Credo.Check.Refactor.UnlessWithElse, []},
Expand Down Expand Up @@ -198,7 +199,6 @@
{Credo.Check.Refactor.MapMap, []},
{Credo.Check.Refactor.ModuleDependencies, []},
{Credo.Check.Refactor.NegatedIsNil, []},
{Credo.Check.Refactor.PassAsyncInTestCases, []},
{Credo.Check.Refactor.PipeChainStart, []},
{Credo.Check.Refactor.RejectFilter, []},
{Credo.Check.Refactor.VariableRebinding, []},
Expand Down
11 changes: 7 additions & 4 deletions test/mindwendel/accounts_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Mindwendel.AccountsTest do
use Mindwendel.DataCase
use Mindwendel.DataCase, async: true
alias Mindwendel.Factory
alias Mindwendel.Accounts
alias Mindwendel.Accounts.User
Expand Down Expand Up @@ -125,13 +125,16 @@ 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 ->
log =
capture_log(fn ->
Accounts.delete_inactive_users()
end)

assert Repo.exists?(from u in User, where: u.id == ^old_user.id)
assert log == ""
# 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
end
end
end
3 changes: 2 additions & 1 deletion test/mindwendel/attachments_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule Mindwendel.AttachmentsTest do
use Mindwendel.DataCase
use Mindwendel.DataCase, async: true

alias Mindwendel.Factory
alias Mindwendel.Attachments

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Mindwendel.Brainstormings.CreateBrainstormingTest do
use Mindwendel.DataCase
use Mindwendel.DataCase, async: true
alias Mindwendel.Brainstormings.BrainstormingModeratingUser
alias Mindwendel.Accounts.BrainstormingUser
alias Mindwendel.Factory
Expand Down
2 changes: 1 addition & 1 deletion test/mindwendel/brainstormings_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Mindwendel.BrainstormingsTest do
alias Mindwendel.Brainstormings.IdeaIdeaLabel
use Mindwendel.DataCase
use Mindwendel.DataCase, async: true
alias Mindwendel.Brainstormings.BrainstormingModeratingUser
alias Mindwendel.Factory

Expand Down
2 changes: 1 addition & 1 deletion test/mindwendel/brainstormings_users_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Mindwendel.AccountsMergeBrainstormingUserTest do
use Mindwendel.DataCase
use Mindwendel.DataCase, async: true
alias Mindwendel.Factory
alias Mindwendel.Accounts
alias Mindwendel.Accounts.User
Expand Down
2 changes: 1 addition & 1 deletion test/mindwendel/csv_formatter_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule MindwendelServices.CSVFormatter do
use Mindwendel.DataCase
use Mindwendel.DataCase, async: true
alias Mindwendel.Factory
alias Mindwendel.CSVFormatter

Expand Down
2 changes: 1 addition & 1 deletion test/mindwendel/help_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Mindwendel.HelpTest do
use Mindwendel.DataCase
use Mindwendel.DataCase, async: true
alias Mindwendel.Factory
alias Mindwendel.Help

Expand Down
2 changes: 1 addition & 1 deletion test/mindwendel/idea_idea_label_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Mindwendel.IdeaIdeaLabelTest do
use Mindwendel.DataCase
use Mindwendel.DataCase, async: true
alias Mindwendel.Factory

alias Mindwendel.Brainstormings.IdeaIdeaLabel
Expand Down
2 changes: 1 addition & 1 deletion test/mindwendel/idea_labels_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Mindwendel.IdeaLabelsTest do
use Mindwendel.DataCase
use Mindwendel.DataCase, async: true
alias Mindwendel.Factory

alias Mindwendel.Ideas
Expand Down
2 changes: 1 addition & 1 deletion test/mindwendel/idea_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Mindwendel.IdeaTest do
use Mindwendel.DataCase
use Mindwendel.DataCase, async: true
alias Mindwendel.Factory

alias Mindwendel.Ideas
Expand Down
2 changes: 1 addition & 1 deletion test/mindwendel/ideas_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Mindwendel.IdeasTest do
use Mindwendel.DataCase
use Mindwendel.DataCase, async: true
alias Mindwendel.Factory

alias Mindwendel.Ideas
Expand Down
2 changes: 1 addition & 1 deletion test/mindwendel/lanes_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Mindwendel.LanesTest do
use Mindwendel.DataCase
use Mindwendel.DataCase, async: true
alias Mindwendel.Lanes
alias Mindwendel.Brainstormings.Lane
import Mindwendel.BrainstormingsFixtures
Expand Down
2 changes: 1 addition & 1 deletion test/mindwendel/likes_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Mindwendel.LikesTest do
use Mindwendel.DataCase
use Mindwendel.DataCase, async: true
alias Mindwendel.Factory
alias Mindwendel.Likes

Expand Down
3 changes: 2 additions & 1 deletion test/mindwendel/services/storage_service_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule Mindwendel.Brainstormings.StorageServiceTest do
use Mindwendel.DataCase
use Mindwendel.DataCase, async: true

alias Mindwendel.Services.StorageService

describe "#store_file" do
Expand Down
2 changes: 1 addition & 1 deletion test/mindwendel/url_preview_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule MindwendelServices.UrlPreviewTest do
use ExUnit.Case
use ExUnit.Case, async: true
alias Mindwendel.UrlPreview

setup do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule MindwendelWeb.BrainstormingChannelTest do
use MindwendelWeb.ChannelCase
use MindwendelWeb.ChannelCase, async: true

alias Mindwendel.Factory
alias Mindwendel.Brainstormings
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule MindwendelWeb.BrainstormingControllerTest do
use MindwendelWeb.ConnCase
use MindwendelWeb.ConnCase, async: true

import Ecto.Query

Expand Down
3 changes: 2 additions & 1 deletion test/mindwendel_web/controllers/file_controller_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule MindwendelWeb.FileControllerTest do
use MindwendelWeb.ConnCase
use MindwendelWeb.ConnCase, async: true

alias Mindwendel.Services.Vault
alias Mindwendel.Factory

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule MindwendelWeb.StaticPageControllerTest do
use MindwendelWeb.ConnCase
use MindwendelWeb.ConnCase, async: true
alias Mindwendel.Factory
alias Mindwendel.Repo

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule MindwendelWeb.Admin.BrainstormingLive.EditTest do
use MindwendelWeb.ConnCase
use MindwendelWeb.ConnCase, async: true
import Phoenix.LiveViewTest

alias Mindwendel.Factory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule MindwendelWeb.BrainstormingLive.ShowIdeaDeleteTest do
use MindwendelWeb.ConnCase
use MindwendelWeb.ConnCase, async: true
import Phoenix.LiveViewTest
alias Mindwendel.Brainstormings

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule MindwendelWeb.BrainstormingLive.ShowIdeaEditTest do
use MindwendelWeb.ConnCase
use MindwendelWeb.ConnCase, async: true
import Phoenix.LiveViewTest
alias Mindwendel.Brainstormings
alias Mindwendel.Accounts.User
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule MindwendelWeb.BrainstormingLive.ShowSortByLabelTest do
use MindwendelWeb.ConnCase
use MindwendelWeb.ConnCase, async: true
import Phoenix.LiveViewTest
alias Mindwendel.Brainstormings

Expand Down
2 changes: 1 addition & 1 deletion test/mindwendel_web/live/brainstorming_live_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule MindwendelWeb.BrainstormingLiveTest do
use MindwendelWeb.ConnCase
use MindwendelWeb.ConnCase, async: true
import Phoenix.LiveViewTest

alias Mindwendel.Brainstormings
Expand Down
8 changes: 5 additions & 3 deletions test/mindwendel_web/live/label_live/captions_test.exs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
defmodule MindwendelWeb.LabelLive.CaptionsTest do
alias MindwendelWeb.LabelLive.CaptionsComponent
alias Mindwendel.Brainstormings
use MindwendelWeb.ConnCase
use MindwendelWeb.ConnCase, async: true

import Phoenix.LiveViewTest

alias Mindwendel.Brainstormings
alias Mindwendel.Factory

alias MindwendelWeb.LabelLive.CaptionsComponent

setup do
%{brainstorming: Factory.insert!(:brainstorming), user: Factory.insert!(:user)}
end
Expand Down
2 changes: 1 addition & 1 deletion test/mindwendel_web/live/live_helpers_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule MindwendelWeb.LiveHelpersTest do
use MindwendelWeb.ConnCase
use MindwendelWeb.ConnCase, async: true
import Phoenix.LiveViewTest

alias Mindwendel.Factory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule MindwendelWeb.ResponseHeaderContentSecurityPolicyTest do
use MindwendelWeb.ConnCase
use MindwendelWeb.ConnCase, async: true

alias Mindwendel.Factory

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Mindwendel.Repo.DataMigrations.MigrateAddLanesToBrainstormingsTest do
Code.require_file("./priv/repo/data_migrations/migrate_add_lanes_to_brainstormings.exs")

use Mindwendel.DataCase
use Mindwendel.DataCase, async: true
alias Mindwendel.Factory
alias Mindwendel.Lanes
alias Mindwendel.Repo.DataMigrations.MigrateAddLanesToBrainstormings
Expand Down
2 changes: 1 addition & 1 deletion test/repo/data_migrations/migrate_idea_labels_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Mindwendel.Repo.DataMigrations.MigrateIdealLabelsTest do
Code.require_file("./priv/repo/data_migrations/migrate_idea_labels.exs")

use Mindwendel.DataCase
use Mindwendel.DataCase, async: true
alias Mindwendel.Factory
alias Mindwendel.Repo
alias Mindwendel.Brainstormings.Brainstorming
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Mindwendel.Repo.DataMigrations.MigrateIdeaLabelsToIdeaIdeaLabelsTest do
Code.require_file("./priv/repo/data_migrations/migrate_idea_labels_to_idea_idea_labels.exs")

use Mindwendel.DataCase
use Mindwendel.DataCase, async: true

alias Mindwendel.Factory
alias Mindwendel.Repo
Expand Down

0 comments on commit 5213ae2

Please sign in to comment.