Skip to content

Commit

Permalink
Pass async to tests, parallelizing them
Browse files Browse the repository at this point in the history
Tests run sync by default. But all of Elixir, essentially, is
built to run tests in parallel/async. Unless you mess with the
global environment there's usually no reason not to run tests
in parallel and it's also best practice to always pass
either `async: true` or `async: false` and a reason why they
can't be run in parallel.

Speeds up the test suite, admittedly not by a lot right now but
it's nice.

I didn't check all the tests for global state, so this may
introduce flakies but on a first couple of runs everything seemed fine.

async:

```
root@812d17669fe3:/app# mix test
*********....................................................................................................................................................
Finished in 0.7 seconds (0.7s async, 0.00s sync)
157 tests, 0 failures, 9 skipped

Randomized with seed 325387
root@812d17669fe3:/app# mix test
***.******...................................................................................................................................................
Finished in 0.6 seconds (0.6s async, 0.00s sync)
157 tests, 0 failures, 9 skipped

Randomized with seed 874856
root@812d17669fe3:/app# mix test
*********....................................................................................................................................................
Finished in 0.7 seconds (0.7s async, 0.00s sync)
157 tests, 0 failures, 9 skipped

Randomized with seed 194987
root@812d17669fe3:/app# mix test
*********....................................................................................................................................................
Finished in 0.6 seconds (0.6s async, 0.00s sync)
157 tests, 0 failures, 9 skipped

Randomized with seed 426291
root@812d17669fe3:/app# mix test
***..******..................................................................................................................................................
Finished in 0.7 seconds (0.7s async, 0.00s sync)
157 tests, 0 failures, 9 skipped

```

sync:

```
root@812d17669fe3:/app# mix test
Compiling 3 files (.ex)
......................................................................................******............08:54:11.449 [error] Postgrex.Protocol (#PID<0.394.0>) disconnected: ** (DBConnection.ConnectionError) owner #PID<0.2162.0> exited
...............***...................................
Finished in 1.6 seconds (0.00s async, 1.6s sync)
157 tests, 0 failures, 9 skipped

Randomized with seed 38709
root@812d17669fe3:/app# mix test
.................................................................................******.........................08:54:18.537 [error] Postgrex.Protocol (#PID<0.373.0>) disconnected: ** (DBConnection.ConnectionError) owner #PID<0.2293.0> exited
.............***.............................
Finished in 1.8 seconds (0.00s async, 1.8s sync)
157 tests, 0 failures, 9 skipped

Randomized with seed 848590
root@812d17669fe3:/app# mix test
......................................................................................******...........08:54:22.337 [error] Postgrex.Protocol (#PID<0.374.0>) disconnected: ** (DBConnection.ConnectionError) owner #PID<0.2118.0> exited
..............***.....................................
Finished in 1.8 seconds (0.00s async, 1.8s sync)
157 tests, 0 failures, 9 skipped

Randomized with seed 729972
root@812d17669fe3:/app# mix test
......................................................................................******........................08:54:26.003 [error] Postgrex.Protocol (#PID<0.375.0>) disconnected: ** (DBConnection.ConnectionError) owner #PID<0.2282.0> exited
.......***...............................
Finished in 1.9 seconds (0.00s async, 1.9s sync)
157 tests, 0 failures, 9 skipped

Randomized with seed 249736
root@812d17669fe3:/app# mix test
..........................................................................******..............................08:54:29.869 [error] Postgrex.Protocol (#PID<0.370.0>) disconnected: ** (DBConnection.ConnectionError) owner #PID<0.2196.0> exited
.........***...................................
Finished in 1.8 seconds (0.00s async, 1.8s sync)
157 tests, 0 failures, 9 skipped

```

Magically it also seems to have gotten rid off that one error, but really don't ask me why.
  • Loading branch information
PragTob committed Nov 3, 2024
1 parent aaa88c0 commit e0e0c84
Show file tree
Hide file tree
Showing 28 changed files with 29 additions and 29 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
2 changes: 1 addition & 1 deletion 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
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
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
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
4 changes: 2 additions & 2 deletions test/mindwendel_web/live/label_live/captions_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule MindwendelWeb.LabelLive.CaptionsTest do
alias MindwendelWeb.LabelLive.CaptionsComponent
alias Mindwendel.Brainstormings
use MindwendelWeb.ConnCase
alias MindwendelWeb.LabelLive.CaptionsComponent
use MindwendelWeb.ConnCase, async: true
import Phoenix.LiveViewTest

alias Mindwendel.Factory
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 e0e0c84

Please sign in to comment.