Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Run tests in async mode where applicable (#2542)
Adam Rutkowski5de43b758da3
diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.ymlindex b523cb86ac..79de048e19 100644--- a/.github/workflows/elixir.yml+++ b/.github/workflows/elixir.yml@@ -13,7 +13,7 @@ jobs:strategy:matrix:- postgres_version: [12,13,14]+ postgres_version: [12, 13, 14]services:postgres:@@ -71,7 +71,7 @@ jobs:- name: Check Credo Warningsrun: mix credo diff --from-git-merge-base origin/master- name: Run tests- run: mix test+ run: mix test --include slow --max-failures 1 --warnings-as-errors- name: Check Dialyzerrun: mix dialyzerenv:diff --git a/config/.env.test b/config/.env.testindex ec2510711f..4f5107ae5b 100644--- a/config/.env.test+++ b/config/.env.test@@ -1,4 +1,4 @@-DATABASE_URL=postgres://postgres:[email protected]:5432/plausible_test+DATABASE_URL=postgres://postgres:[email protected]:5432/plausible_test?pool_size=40CLICKHOUSE_DATABASE_URL=http://127.0.0.1:8123/plausible_testSECRET_KEY_BASE=/njrhntbycvastyvtk1zycwfm981vpo/0xrvwjjvemdakc/vsvbrevlwsc6u8rcgBASE_URL=http://localhost:8000diff --git a/test/plausible/google/api_test.exs b/test/plausible/google/api_test.exsindex 14dfcbeeef..29a4d4ecd8 100644--- a/test/plausible/google/api_test.exs+++ b/test/plausible/google/api_test.exs@@ -1,5 +1,5 @@defmodule Plausible.Google.ApiTest do- use Plausible.DataCase, async: true+ use Plausible.DataCase, async: falseuse ExVCR.Mock, adapter: ExVCR.Adapter.Finchalias Plausible.Google.Api@@ -25,6 +25,7 @@ defmodule Plausible.Google.ApiTest do|> Enum.map(&File.read!/1)|> Enum.map(&Jason.decode!/1)+ @tag :slowtest "import_analytics/4 refreshes OAuth token when needed", %{site: site} dopast = DateTime.add(DateTime.utc_now(), -3600, :second)auth = {"redacted_access_token", "redacted_refresh_token", DateTime.to_iso8601(past)}diff --git a/test/plausible/google/buffer_test.exs b/test/plausible/google/buffer_test.exsindex bb14f1212c..8b57e2254e 100644--- a/test/plausible/google/buffer_test.exs+++ b/test/plausible/google/buffer_test.exs@@ -39,6 +39,7 @@ defmodule Plausible.Google.BufferTest doassert imported_count(site, "imported_visitors") == 10, "expected to have flushed"end+ @tag :slowtest "insert_many/3 uses separate buffers for each table", %{site: site} do{:ok, pid} = Buffer.start_link()@@ -72,6 +73,7 @@ defmodule Plausible.Google.BufferTest doassert imported_count(site, "imported_visitors") == 50, "expected to have flushed"end+ @tag :slowtest "flush/2 flushes all buffers", %{site: site} do{:ok, pid} = Buffer.start_link()diff --git a/test/plausible/google/vcr_test.exs b/test/plausible/google/vcr_test.exsindex 1eff00be41..08151266b8 100644--- a/test/plausible/google/vcr_test.exs+++ b/test/plausible/google/vcr_test.exs@@ -7,6 +7,7 @@ defmodule Plausible.Google.Api.VCRTest do# We need real HTTP Client for VCR testssetup_patch_env(:http_impl, Plausible.HTTPClient)+ @tag :slowtest "imports page views from Google Analytics", %{site: site} douse_cassette "google_analytics_import#1", match_requests_on: [:request_body] doview_id = "54297898"diff --git a/test/plausible_web/controllers/api/external_controller_test.exs b/test/plausible_web/controllers/api/external_controller_test.exsindex cab75db5c2..315b7423a7 100644--- a/test/plausible_web/controllers/api/external_controller_test.exs+++ b/test/plausible_web/controllers/api/external_controller_test.exs@@ -97,11 +97,16 @@ defmodule PlausibleWeb.Api.ExternalControllerTest doscreen_width: 1440}+ t1 = System.convert_time_unit(System.monotonic_time(), :native, :millisecond)+conn|> put_req_header("user-agent", @user_agent)|> post("/api/event", params)- :timer.sleep(1500)+ t2 = System.convert_time_unit(System.monotonic_time(), :native, :millisecond)++ # timestamps are in second precision, so we need to wait for it to flip+ Process.sleep(1000 - (t2 - t1))conn|> put_req_header("user-agent", @user_agent)diff --git a/test/plausible_web/controllers/api/external_sites_controller_test.exs b/test/plausible_web/controllers/api/external_sites_controller_test.exsindex d2b3d0ef79..9706ca5c5e 100644--- a/test/plausible_web/controllers/api/external_sites_controller_test.exs+++ b/test/plausible_web/controllers/api/external_sites_controller_test.exs@@ -1,5 +1,5 @@defmodule PlausibleWeb.Api.ExternalSitesControllerTest do- use PlausibleWeb.ConnCase+ use PlausibleWeb.ConnCase, async: falseuse Plausible.Reposetup %{conn: conn} do@@ -62,7 +62,7 @@ defmodule PlausibleWeb.Api.ExternalSitesControllerTest doendtest "does not allow creating more sites than the limit", %{conn: conn, user: user} do- Application.put_env(:plausible, :site_limit, 3)+ patch_env(:site_limit, 3)insert(:site, members: [user])insert(:site, members: [user])insert(:site, members: [user])diff --git a/test/plausible_web/controllers/api/internal_controller_test.exs b/test/plausible_web/controllers/api/internal_controller_test.exsindex f16bf8e5d1..65821f796b 100644--- a/test/plausible_web/controllers/api/internal_controller_test.exs+++ b/test/plausible_web/controllers/api/internal_controller_test.exs@@ -1,5 +1,5 @@defmodule PlausibleWeb.Api.InternalControllerTest do- use PlausibleWeb.ConnCase+ use PlausibleWeb.ConnCase, async: trueuse Plausible.Repodescribe "GET /api/:domain/status" dodiff --git a/test/plausible_web/controllers/api/paddle_controller_test.exs b/test/plausible_web/controllers/api/paddle_controller_test.exsindex 2eb63e9b09..2c1398d53b 100644--- a/test/plausible_web/controllers/api/paddle_controller_test.exs+++ b/test/plausible_web/controllers/api/paddle_controller_test.exs@@ -1,5 +1,5 @@defmodule PlausibleWeb.Api.PaddleControllerTest do- use PlausibleWeb.ConnCase+ use PlausibleWeb.ConnCase, async: trueuse Plausible.Repo@body %{diff --git a/test/plausible_web/controllers/auth_controller_test.exs b/test/plausible_web/controllers/auth_controller_test.exsindex c563c7bf64..7da7c544f8 100644--- a/test/plausible_web/controllers/auth_controller_test.exs+++ b/test/plausible_web/controllers/auth_controller_test.exs@@ -1,5 +1,5 @@defmodule PlausibleWeb.AuthControllerTest do- use PlausibleWeb.ConnCase+ use PlausibleWeb.ConnCase, async: trueuse Bamboo.Testuse Plausible.Repo@@ -15,9 +15,12 @@ defmodule PlausibleWeb.AuthControllerTest doenddescribe "POST /register" do- test "registering sends an activation link", %{conn: conn} do+ setup domock_captcha_success()+ :ok+ end+ test "registering sends an activation link", %{conn: conn} dopost(conn, "/register",user: %{name: "Jane Doe",@@ -33,8 +36,6 @@ defmodule PlausibleWeb.AuthControllerTest doendtest "user is redirected to activate page after registration", %{conn: conn} do- mock_captcha_success()-conn =post(conn, "/register",user: %{@@ -49,8 +50,6 @@ defmodule PlausibleWeb.AuthControllerTest doendtest "creates user record", %{conn: conn} do- mock_captcha_success()-post(conn, "/register",user: %{name: "Jane Doe",@@ -65,8 +64,6 @@ defmodule PlausibleWeb.AuthControllerTest doendtest "logs the user in", %{conn: conn} do- mock_captcha_success()-conn =post(conn, "/register",user: %{@@ -81,8 +78,6 @@ defmodule PlausibleWeb.AuthControllerTest doendtest "user is redirected to activation after registration", %{conn: conn} do- mock_captcha_success()-conn =post(conn, "/register",user: %{@@ -95,22 +90,6 @@ defmodule PlausibleWeb.AuthControllerTest doassert redirected_to(conn) == "/activate"end-- test "renders captcha errors in case of captcha input verification failure", %{conn: conn} do- mock_captcha_failure()-- conn =- post(conn, "/register",- user: %{- name: "Jane Doe",- email: "[email protected]",- password: "very-secret",- password_confirmation: "very-secret"- }- )-- assert html_response(conn, 200) =~ "Please complete the captcha"- endenddescribe "GET /register/invitations/:invitation_id" do@@ -134,6 +113,7 @@ defmodule PlausibleWeb.AuthControllerTest dodescribe "POST /register/invitation/:invitation_id" dosetup do+ mock_captcha_success()inviter = insert(:user)site = insert(:site, members: [inviter])@@ -149,8 +129,6 @@ defmodule PlausibleWeb.AuthControllerTest doendtest "registering sends an activation link", %{conn: conn, invitation: invitation} do- mock_captcha_success()-post(conn, "/register/invitation/#{invitation.invitation_id}",user: %{name: "Jane Doe",@@ -169,8 +147,6 @@ defmodule PlausibleWeb.AuthControllerTest doconn: conn,invitation: invitation} do- mock_captcha_success()-conn =post(conn, "/register/invitation/#{invitation.invitation_id}",user: %{@@ -185,8 +161,6 @@ defmodule PlausibleWeb.AuthControllerTest doendtest "creates user record", %{conn: conn, invitation: invitation} do- mock_captcha_success()-post(conn, "/register/invitation/#{invitation.invitation_id}",user: %{name: "Jane Doe",@@ -204,8 +178,6 @@ defmodule PlausibleWeb.AuthControllerTest doconn: conn,invitation: invitation} do- mock_captcha_success()-post(conn, "/register/invitation/#{invitation.invitation_id}",user: %{name: "Jane Doe",@@ -220,8 +192,6 @@ defmodule PlausibleWeb.AuthControllerTest doendtest "logs the user in", %{conn: conn, invitation: invitation} do- mock_captcha_success()-conn =post(conn, "/register/invitation/#{invitation.invitation_id}",user: %{@@ -236,8 +206,6 @@ defmodule PlausibleWeb.AuthControllerTest doendtest "user is redirected to activation after registration", %{conn: conn} do- mock_captcha_success()-conn =post(conn, "/register",user: %{@@ -250,13 +218,29 @@ defmodule PlausibleWeb.AuthControllerTest doassert redirected_to(conn) == "/activate"end+ end++ describe "captcha failure" do+ setup do+ mock_captcha_failure()+ inviter = insert(:user)+ site = insert(:site, members: [inviter])++ invitation =+ insert(:invitation,+ site_id: site.id,+ inviter: inviter,+ email: "[email protected]",+ role: :admin+ )++ {:ok, %{site: site, invitation: invitation}}+ endtest "renders captcha errors in case of captcha input verification failure", %{conn: conn,invitation: invitation} do- mock_captcha_failure()-conn =post(conn, "/register/invitation/#{invitation.invitation_id}",user: %{diff --git a/test/plausible_web/controllers/billing_controller_test.exs b/test/plausible_web/controllers/billing_controller_test.exsindex 7daedae035..bec3abf824 100644--- a/test/plausible_web/controllers/billing_controller_test.exs+++ b/test/plausible_web/controllers/billing_controller_test.exs@@ -1,5 +1,5 @@defmodule PlausibleWeb.BillingControllerTest do- use PlausibleWeb.ConnCase+ use PlausibleWeb.ConnCase, async: truedescribe "GET /upgrade" dosetup [:create_user, :log_in]diff --git a/test/plausible_web/controllers/unsubscribe_controller_test.exs b/test/plausible_web/controllers/unsubscribe_controller_test.exsindex 56f1afc677..d955270646 100644--- a/test/plausible_web/controllers/unsubscribe_controller_test.exs+++ b/test/plausible_web/controllers/unsubscribe_controller_test.exs@@ -1,5 +1,5 @@defmodule PlausibleWeb.UnsubscribeControllerTest do- use PlausibleWeb.ConnCase+ use PlausibleWeb.ConnCase, async: trueuse Plausible.Repodescribe "GET /sites/:website/weekly-report/unsubscribe" dodiff --git a/test/plausible_web/plugs/auth_plug_test.exs b/test/plausible_web/plugs/auth_plug_test.exsindex 9598610ecd..689195bdc6 100644--- a/test/plausible_web/plugs/auth_plug_test.exs+++ b/test/plausible_web/plugs/auth_plug_test.exs@@ -1,5 +1,5 @@defmodule PlausibleWeb.AuthPlugTest do- use Plausible.DataCase+ use Plausible.DataCase, async: trueuse Plug.Testalias PlausibleWeb.AuthPlugdiff --git a/test/plausible_web/plugs/favicon_test.exs b/test/plausible_web/plugs/favicon_test.exsindex 1fa89a9f02..a62e4232a4 100644--- a/test/plausible_web/plugs/favicon_test.exs+++ b/test/plausible_web/plugs/favicon_test.exs@@ -1,5 +1,5 @@defmodule PlausibleWeb.FaviconTest do- use Plausible.DataCase+ use Plausible.DataCase, async: trueuse Plug.Testalias PlausibleWeb.Favicondiff --git a/test/plausible_web/plugs/firewall_test.exs b/test/plausible_web/plugs/firewall_test.exsindex a698e2f14a..ef73547eb0 100644--- a/test/plausible_web/plugs/firewall_test.exs+++ b/test/plausible_web/plugs/firewall_test.exs@@ -7,10 +7,7 @@ defmodule PlausibleWeb.FirewallTest do@blocked_ip "127.0.0.2"@opts [blocklist: [@blocked_ip]]- setup do- Application.put_env(:plausible, PlausibleWeb.Firewall, blocklist: [@blocked_ip])- :ok- end+ setup_patch_env(PlausibleWeb.Firewall, blocklist: [@blocked_ip])test "ignores request if IP is allowed" doconn =diff --git a/test/plausible_web/plugs/tracker_test.exs b/test/plausible_web/plugs/tracker_test.exsindex 7dd3cba564..c99de70da8 100644--- a/test/plausible_web/plugs/tracker_test.exs+++ b/test/plausible_web/plugs/tracker_test.exs@@ -13,7 +13,7 @@ defmodule PlausibleWeb.TrackerTest doIf you're making changes in the tracker template files (`src/plausible.js`, `compile.js`),do regenerate the files before running tests, so they're up to date."""- use PlausibleWeb.ConnCase+ use PlausibleWeb.ConnCase, async: trueuse Plug.Testtest "returns legacy script p.js" dodiff --git a/test/test_helper.exs b/test/test_helper.exsindex 0987bdbea1..85358b3dff 100644--- a/test/test_helper.exs+++ b/test/test_helper.exs@@ -1,6 +1,6 @@{:ok, _} = Application.ensure_all_started(:ex_machina)Plausible.Test.ClickhouseSetup.run()Mox.defmock(Plausible.HTTPClient.Mock, for: Plausible.HTTPClient.Interface)-ExUnit.start()+ExUnit.start(exclude: :slow)Application.ensure_all_started(:double)Ecto.Adapters.SQL.Sandbox.mode(Plausible.Repo, :manual)