Refactor test runtime ownership
This commit is contained in:
@@ -5,19 +5,6 @@ defmodule Parrhesia.Application do
|
|||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def start(_type, _args) do
|
def start(_type, _args) do
|
||||||
children = [
|
Parrhesia.Runtime.start_link(name: Parrhesia.Supervisor)
|
||||||
Parrhesia.Telemetry,
|
|
||||||
Parrhesia.Config,
|
|
||||||
Parrhesia.Storage.Supervisor,
|
|
||||||
Parrhesia.Subscriptions.Supervisor,
|
|
||||||
Parrhesia.Auth.Supervisor,
|
|
||||||
Parrhesia.Sync.Supervisor,
|
|
||||||
Parrhesia.Policy.Supervisor,
|
|
||||||
Parrhesia.Web.Endpoint,
|
|
||||||
Parrhesia.Tasks.Supervisor
|
|
||||||
]
|
|
||||||
|
|
||||||
opts = [strategy: :one_for_one, name: Parrhesia.Supervisor]
|
|
||||||
Supervisor.start_link(children, opts)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
29
lib/parrhesia/runtime.ex
Normal file
29
lib/parrhesia/runtime.ex
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
defmodule Parrhesia.Runtime do
|
||||||
|
@moduledoc false
|
||||||
|
|
||||||
|
use Supervisor
|
||||||
|
|
||||||
|
def start_link(opts \\ []) do
|
||||||
|
name = Keyword.get(opts, :name, Parrhesia.Supervisor)
|
||||||
|
Supervisor.start_link(__MODULE__, opts, name: name)
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def init(_opts) do
|
||||||
|
Supervisor.init(children(), strategy: :one_for_one)
|
||||||
|
end
|
||||||
|
|
||||||
|
def children do
|
||||||
|
[
|
||||||
|
Parrhesia.Telemetry,
|
||||||
|
Parrhesia.Config,
|
||||||
|
Parrhesia.Storage.Supervisor,
|
||||||
|
Parrhesia.Subscriptions.Supervisor,
|
||||||
|
Parrhesia.Auth.Supervisor,
|
||||||
|
Parrhesia.Sync.Supervisor,
|
||||||
|
Parrhesia.Policy.Supervisor,
|
||||||
|
Parrhesia.Web.Endpoint,
|
||||||
|
Parrhesia.Tasks.Supervisor
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
||||||
4
mix.exs
4
mix.exs
@@ -6,6 +6,7 @@ defmodule Parrhesia.MixProject do
|
|||||||
app: :parrhesia,
|
app: :parrhesia,
|
||||||
version: "0.5.0",
|
version: "0.5.0",
|
||||||
elixir: "~> 1.18",
|
elixir: "~> 1.18",
|
||||||
|
elixirc_paths: elixirc_paths(Mix.env()),
|
||||||
start_permanent: Mix.env() == :prod,
|
start_permanent: Mix.env() == :prod,
|
||||||
deps: deps(),
|
deps: deps(),
|
||||||
aliases: aliases()
|
aliases: aliases()
|
||||||
@@ -20,6 +21,9 @@ defmodule Parrhesia.MixProject do
|
|||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp elixirc_paths(:test), do: ["lib", "test/support"]
|
||||||
|
defp elixirc_paths(_env), do: ["lib"]
|
||||||
|
|
||||||
def cli do
|
def cli do
|
||||||
[preferred_envs: [precommit: :test, bench: :test]]
|
[preferred_envs: [precommit: :test, bench: :test]]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
defmodule Parrhesia.API.ACLTest do
|
defmodule Parrhesia.API.ACLTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false, sandbox: true
|
||||||
|
|
||||||
alias Ecto.Adapters.SQL.Sandbox
|
|
||||||
alias Parrhesia.API.ACL
|
alias Parrhesia.API.ACL
|
||||||
alias Parrhesia.API.RequestContext
|
alias Parrhesia.API.RequestContext
|
||||||
alias Parrhesia.Repo
|
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
:ok = Sandbox.checkout(Repo)
|
|
||||||
|
|
||||||
previous_acl = Application.get_env(:parrhesia, :acl, [])
|
previous_acl = Application.get_env(:parrhesia, :acl, [])
|
||||||
|
|
||||||
Application.put_env(
|
Application.put_env(
|
||||||
|
|||||||
@@ -1,16 +1,9 @@
|
|||||||
defmodule Parrhesia.API.EventsTest do
|
defmodule Parrhesia.API.EventsTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false, sandbox: true
|
||||||
|
|
||||||
alias Ecto.Adapters.SQL.Sandbox
|
|
||||||
alias Parrhesia.API.Events
|
alias Parrhesia.API.Events
|
||||||
alias Parrhesia.API.RequestContext
|
alias Parrhesia.API.RequestContext
|
||||||
alias Parrhesia.Protocol.EventValidator
|
alias Parrhesia.Protocol.EventValidator
|
||||||
alias Parrhesia.Repo
|
|
||||||
|
|
||||||
setup do
|
|
||||||
:ok = Sandbox.checkout(Repo)
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
test "publish stores valid events through the shared API" do
|
test "publish stores valid events through the shared API" do
|
||||||
event = valid_event()
|
event = valid_event()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
defmodule Parrhesia.API.IdentityTest do
|
defmodule Parrhesia.API.IdentityTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false
|
||||||
|
|
||||||
alias Parrhesia.API.Auth
|
alias Parrhesia.API.Auth
|
||||||
alias Parrhesia.API.Identity
|
alias Parrhesia.API.Identity
|
||||||
|
|||||||
@@ -1,19 +1,10 @@
|
|||||||
defmodule Parrhesia.API.StreamTest do
|
defmodule Parrhesia.API.StreamTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false, sandbox: true
|
||||||
|
|
||||||
alias Ecto.Adapters.SQL.Sandbox
|
|
||||||
alias Parrhesia.API.Events
|
alias Parrhesia.API.Events
|
||||||
alias Parrhesia.API.RequestContext
|
alias Parrhesia.API.RequestContext
|
||||||
alias Parrhesia.API.Stream
|
alias Parrhesia.API.Stream
|
||||||
alias Parrhesia.Protocol.EventValidator
|
alias Parrhesia.Protocol.EventValidator
|
||||||
alias Parrhesia.Repo
|
|
||||||
|
|
||||||
setup do
|
|
||||||
ensure_repo_started()
|
|
||||||
ensure_stream_runtime_started()
|
|
||||||
:ok = Sandbox.checkout(Repo)
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
test "subscribe streams catch-up events followed by eose" do
|
test "subscribe streams catch-up events followed by eose" do
|
||||||
event = valid_event()
|
event = valid_event()
|
||||||
@@ -79,24 +70,4 @@ defmodule Parrhesia.API.StreamTest do
|
|||||||
defp recalculate_event_id(event) do
|
defp recalculate_event_id(event) do
|
||||||
Map.put(event, "id", EventValidator.compute_id(event))
|
Map.put(event, "id", EventValidator.compute_id(event))
|
||||||
end
|
end
|
||||||
|
|
||||||
defp ensure_stream_runtime_started do
|
|
||||||
if is_nil(Process.whereis(Parrhesia.API.Stream.Supervisor)) do
|
|
||||||
case start_supervised({Parrhesia.Subscriptions.Supervisor, []}) do
|
|
||||||
{:ok, _pid} -> :ok
|
|
||||||
{:error, {:already_started, _pid}} -> :ok
|
|
||||||
end
|
|
||||||
else
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp ensure_repo_started do
|
|
||||||
if is_nil(Process.whereis(Repo)) do
|
|
||||||
_ = start_supervised(Repo)
|
|
||||||
:ok
|
|
||||||
else
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,16 +1,9 @@
|
|||||||
defmodule Parrhesia.API.SyncTest do
|
defmodule Parrhesia.API.SyncTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false, sandbox: true
|
||||||
|
|
||||||
alias Ecto.Adapters.SQL.Sandbox
|
|
||||||
alias Parrhesia.API.Admin
|
alias Parrhesia.API.Admin
|
||||||
alias Parrhesia.API.Sync
|
alias Parrhesia.API.Sync
|
||||||
alias Parrhesia.API.Sync.Manager
|
alias Parrhesia.API.Sync.Manager
|
||||||
alias Parrhesia.Repo
|
|
||||||
|
|
||||||
setup do
|
|
||||||
:ok = Sandbox.checkout(Repo)
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
test "put_server stores normalized config and persists it across restart" do
|
test "put_server stores normalized config and persists it across restart" do
|
||||||
{manager, path, pid} = start_sync_manager()
|
{manager, path, pid} = start_sync_manager()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
defmodule Parrhesia.ApplicationTest do
|
defmodule Parrhesia.ApplicationTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false
|
||||||
|
|
||||||
test "starts the core supervision tree" do
|
test "starts the core supervision tree" do
|
||||||
assert is_pid(Process.whereis(Parrhesia.Supervisor))
|
assert is_pid(Process.whereis(Parrhesia.Supervisor))
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
defmodule Parrhesia.E2E.NakCliTest do
|
defmodule Parrhesia.E2E.NakCliTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false
|
||||||
|
|
||||||
@moduletag :nak_e2e
|
@moduletag :nak_e2e
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
defmodule Parrhesia.Fanout.MultiNodeTest do
|
defmodule Parrhesia.Fanout.MultiNodeTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false
|
||||||
|
|
||||||
alias Parrhesia.Fanout.MultiNode
|
alias Parrhesia.Fanout.MultiNode
|
||||||
alias Parrhesia.Subscriptions.Index
|
alias Parrhesia.Subscriptions.Index
|
||||||
|
|||||||
@@ -1,17 +1,13 @@
|
|||||||
defmodule Parrhesia.FaultInjectionGroupFlowTest do
|
defmodule Parrhesia.FaultInjectionGroupFlowTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false, sandbox: true
|
||||||
|
|
||||||
alias Ecto.Adapters.SQL.Sandbox
|
|
||||||
alias Parrhesia.Protocol.EventValidator
|
alias Parrhesia.Protocol.EventValidator
|
||||||
alias Parrhesia.Repo
|
|
||||||
alias Parrhesia.Storage
|
alias Parrhesia.Storage
|
||||||
alias Parrhesia.TestSupport.FailingEvents
|
alias Parrhesia.TestSupport.FailingEvents
|
||||||
alias Parrhesia.TestSupport.PermissiveModeration
|
alias Parrhesia.TestSupport.PermissiveModeration
|
||||||
alias Parrhesia.Web.Connection
|
alias Parrhesia.Web.Connection
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
:ok = Sandbox.checkout(Repo)
|
|
||||||
|
|
||||||
previous_storage = Application.get_env(:parrhesia, :storage, [])
|
previous_storage = Application.get_env(:parrhesia, :storage, [])
|
||||||
|
|
||||||
Application.put_env(
|
Application.put_env(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
defmodule Parrhesia.FaultInjectionTest do
|
defmodule Parrhesia.FaultInjectionTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false
|
||||||
|
|
||||||
alias Parrhesia.Protocol.EventValidator
|
alias Parrhesia.Protocol.EventValidator
|
||||||
alias Parrhesia.Web.Connection
|
alias Parrhesia.Web.Connection
|
||||||
|
|||||||
@@ -1,16 +1,9 @@
|
|||||||
defmodule Parrhesia.Groups.FlowTest do
|
defmodule Parrhesia.Groups.FlowTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false, sandbox: true
|
||||||
|
|
||||||
alias Ecto.Adapters.SQL.Sandbox
|
|
||||||
alias Parrhesia.Groups.Flow
|
alias Parrhesia.Groups.Flow
|
||||||
alias Parrhesia.Repo
|
|
||||||
alias Parrhesia.Storage
|
alias Parrhesia.Storage
|
||||||
|
|
||||||
setup do
|
|
||||||
:ok = Sandbox.checkout(Repo)
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
test "handles membership request kinds by upserting group memberships" do
|
test "handles membership request kinds by upserting group memberships" do
|
||||||
event = %{
|
event = %{
|
||||||
"kind" => 8_000,
|
"kind" => 8_000,
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
defmodule Parrhesia.Negentropy.SessionsTest do
|
defmodule Parrhesia.Negentropy.SessionsTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false, sandbox: true
|
||||||
|
|
||||||
alias Ecto.Adapters.SQL.Sandbox
|
|
||||||
alias Parrhesia.Negentropy.Engine
|
alias Parrhesia.Negentropy.Engine
|
||||||
alias Parrhesia.Negentropy.Message
|
alias Parrhesia.Negentropy.Message
|
||||||
alias Parrhesia.Negentropy.Sessions
|
alias Parrhesia.Negentropy.Sessions
|
||||||
@@ -9,20 +8,6 @@ defmodule Parrhesia.Negentropy.SessionsTest do
|
|||||||
alias Parrhesia.Repo
|
alias Parrhesia.Repo
|
||||||
alias Parrhesia.Storage.Adapters.Postgres.Events
|
alias Parrhesia.Storage.Adapters.Postgres.Events
|
||||||
|
|
||||||
setup_all do
|
|
||||||
if is_nil(Process.whereis(Repo)) do
|
|
||||||
start_supervised!(Repo)
|
|
||||||
end
|
|
||||||
|
|
||||||
Sandbox.mode(Repo, :manual)
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
setup do
|
|
||||||
:ok = Sandbox.checkout(Repo)
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
test "opens, responds, advances and closes sessions" do
|
test "opens, responds, advances and closes sessions" do
|
||||||
server = start_supervised!({Sessions, name: nil})
|
server = start_supervised!({Sessions, name: nil})
|
||||||
Sandbox.allow(Repo, self(), server)
|
Sandbox.allow(Repo, self(), server)
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
defmodule Parrhesia.Performance.LoadSoakTest do
|
defmodule Parrhesia.Performance.LoadSoakTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false, sandbox: true
|
||||||
|
|
||||||
alias Ecto.Adapters.SQL.Sandbox
|
|
||||||
alias Parrhesia.Repo
|
|
||||||
alias Parrhesia.Web.Connection
|
alias Parrhesia.Web.Connection
|
||||||
|
|
||||||
@tag :performance
|
@tag :performance
|
||||||
test "fanout enqueue/drain stays within relaxed p95 budget" do
|
test "fanout enqueue/drain stays within relaxed p95 budget" do
|
||||||
:ok = Sandbox.checkout(Repo)
|
|
||||||
|
|
||||||
{:ok, state} = Connection.init(subscription_index: nil, max_outbound_queue: 10_000)
|
{:ok, state} = Connection.init(subscription_index: nil, max_outbound_queue: 10_000)
|
||||||
|
|
||||||
req_payload = JSON.encode!(["REQ", "sub-load", %{"kinds" => [1]}])
|
req_payload = JSON.encode!(["REQ", "sub-load", %{"kinds" => [1]}])
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
defmodule Parrhesia.Policy.EventPolicyTest do
|
defmodule Parrhesia.Policy.EventPolicyTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false
|
||||||
|
|
||||||
alias Parrhesia.Policy.EventPolicy
|
alias Parrhesia.Policy.EventPolicy
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
defmodule Parrhesia.Protocol.EventValidatorSignatureTest do
|
defmodule Parrhesia.Protocol.EventValidatorSignatureTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false
|
||||||
|
|
||||||
alias Parrhesia.Protocol.EventValidator
|
alias Parrhesia.Protocol.EventValidator
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
defmodule Parrhesia.Storage.Adapters.Memory.AdapterTest do
|
defmodule Parrhesia.Storage.Adapters.Memory.AdapterTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false
|
||||||
|
|
||||||
alias Parrhesia.Storage.Adapters.Memory.ACL
|
alias Parrhesia.Storage.Adapters.Memory.ACL
|
||||||
alias Parrhesia.Storage.Adapters.Memory.Admin
|
alias Parrhesia.Storage.Adapters.Memory.Admin
|
||||||
|
|||||||
@@ -1,26 +1,11 @@
|
|||||||
defmodule Parrhesia.Storage.Adapters.Postgres.AdapterContractTest do
|
defmodule Parrhesia.Storage.Adapters.Postgres.AdapterContractTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false, sandbox: true
|
||||||
|
|
||||||
alias Ecto.Adapters.SQL.Sandbox
|
|
||||||
alias Parrhesia.Repo
|
|
||||||
alias Parrhesia.Storage.Adapters.Postgres.ACL
|
alias Parrhesia.Storage.Adapters.Postgres.ACL
|
||||||
alias Parrhesia.Storage.Adapters.Postgres.Admin
|
alias Parrhesia.Storage.Adapters.Postgres.Admin
|
||||||
alias Parrhesia.Storage.Adapters.Postgres.Groups
|
alias Parrhesia.Storage.Adapters.Postgres.Groups
|
||||||
alias Parrhesia.Storage.Adapters.Postgres.Moderation
|
alias Parrhesia.Storage.Adapters.Postgres.Moderation
|
||||||
|
|
||||||
setup_all do
|
|
||||||
if is_nil(Process.whereis(Repo)) do
|
|
||||||
start_supervised!(Repo)
|
|
||||||
end
|
|
||||||
|
|
||||||
Sandbox.mode(Repo, :manual)
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
setup do
|
|
||||||
:ok = Sandbox.checkout(Repo)
|
|
||||||
end
|
|
||||||
|
|
||||||
test "moderation adapter persists pubkey/event/ip block state" do
|
test "moderation adapter persists pubkey/event/ip block state" do
|
||||||
pubkey = String.duplicate("a", 64)
|
pubkey = String.duplicate("a", 64)
|
||||||
event_id = String.duplicate("b", 64)
|
event_id = String.duplicate("b", 64)
|
||||||
|
|||||||
@@ -1,16 +1,9 @@
|
|||||||
defmodule Parrhesia.Storage.Adapters.Postgres.EventsLifecycleTest do
|
defmodule Parrhesia.Storage.Adapters.Postgres.EventsLifecycleTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false, sandbox: true
|
||||||
|
|
||||||
alias Ecto.Adapters.SQL.Sandbox
|
|
||||||
alias Parrhesia.Protocol.EventValidator
|
alias Parrhesia.Protocol.EventValidator
|
||||||
alias Parrhesia.Repo
|
|
||||||
alias Parrhesia.Storage.Adapters.Postgres.Events
|
alias Parrhesia.Storage.Adapters.Postgres.Events
|
||||||
|
|
||||||
setup do
|
|
||||||
:ok = Sandbox.checkout(Repo)
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
test "event tags round-trip without truncation" do
|
test "event tags round-trip without truncation" do
|
||||||
tagged_event =
|
tagged_event =
|
||||||
event(%{
|
event(%{
|
||||||
|
|||||||
@@ -1,24 +1,9 @@
|
|||||||
defmodule Parrhesia.Storage.Adapters.Postgres.EventsQueryCountTest do
|
defmodule Parrhesia.Storage.Adapters.Postgres.EventsQueryCountTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false, sandbox: true
|
||||||
|
|
||||||
alias Ecto.Adapters.SQL.Sandbox
|
|
||||||
alias Parrhesia.Protocol.EventValidator
|
alias Parrhesia.Protocol.EventValidator
|
||||||
alias Parrhesia.Repo
|
|
||||||
alias Parrhesia.Storage.Adapters.Postgres.Events
|
alias Parrhesia.Storage.Adapters.Postgres.Events
|
||||||
|
|
||||||
setup_all do
|
|
||||||
if is_nil(Process.whereis(Repo)) do
|
|
||||||
start_supervised!(Repo)
|
|
||||||
end
|
|
||||||
|
|
||||||
Sandbox.mode(Repo, :manual)
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
setup do
|
|
||||||
:ok = Sandbox.checkout(Repo)
|
|
||||||
end
|
|
||||||
|
|
||||||
test "query/3 translates NIP filters including tag filters" do
|
test "query/3 translates NIP filters including tag filters" do
|
||||||
author = String.duplicate("a", 64)
|
author = String.duplicate("a", 64)
|
||||||
other_author = String.duplicate("b", 64)
|
other_author = String.duplicate("b", 64)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
defmodule Parrhesia.Storage.Adapters.Postgres.EventsTest do
|
defmodule Parrhesia.Storage.Adapters.Postgres.EventsTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false
|
||||||
|
|
||||||
alias Parrhesia.Protocol.EventValidator
|
alias Parrhesia.Protocol.EventValidator
|
||||||
alias Parrhesia.Storage.Adapters.Postgres.Events
|
alias Parrhesia.Storage.Adapters.Postgres.Events
|
||||||
|
|||||||
@@ -1,22 +1,11 @@
|
|||||||
defmodule Parrhesia.Storage.Adapters.Postgres.QueryPlanRegressionTest do
|
defmodule Parrhesia.Storage.Adapters.Postgres.QueryPlanRegressionTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false, sandbox: true
|
||||||
|
|
||||||
alias Ecto.Adapters.SQL.Sandbox
|
|
||||||
alias Parrhesia.Protocol.EventValidator
|
alias Parrhesia.Protocol.EventValidator
|
||||||
alias Parrhesia.Repo
|
alias Parrhesia.Repo
|
||||||
alias Parrhesia.Storage.Adapters.Postgres.Events
|
alias Parrhesia.Storage.Adapters.Postgres.Events
|
||||||
|
|
||||||
setup_all do
|
|
||||||
if is_nil(Process.whereis(Repo)) do
|
|
||||||
start_supervised!(Repo)
|
|
||||||
end
|
|
||||||
|
|
||||||
Sandbox.mode(Repo, :manual)
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
:ok = Sandbox.checkout(Repo)
|
|
||||||
:ok = Repo.query!("SET enable_seqscan TO off") |> then(fn _ -> :ok end)
|
:ok = Repo.query!("SET enable_seqscan TO off") |> then(fn _ -> :ok end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,8 @@
|
|||||||
defmodule Parrhesia.Storage.PartitionsTest do
|
defmodule Parrhesia.Storage.PartitionsTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false, sandbox: true
|
||||||
|
|
||||||
alias Ecto.Adapters.SQL.Sandbox
|
|
||||||
alias Parrhesia.Repo
|
|
||||||
alias Parrhesia.Storage.Partitions
|
alias Parrhesia.Storage.Partitions
|
||||||
|
|
||||||
setup do
|
|
||||||
:ok = Sandbox.checkout(Repo)
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
test "list_partitions returns partition tables" do
|
test "list_partitions returns partition tables" do
|
||||||
partitions = Partitions.list_partitions()
|
partitions = Partitions.list_partitions()
|
||||||
assert is_list(partitions)
|
assert is_list(partitions)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
defmodule Parrhesia.StorageTest do
|
defmodule Parrhesia.StorageTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false
|
||||||
|
|
||||||
alias Parrhesia.Storage
|
alias Parrhesia.Storage
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +1,16 @@
|
|||||||
defmodule Parrhesia.Sync.WorkerTest do
|
defmodule Parrhesia.Sync.WorkerTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false, sandbox: :shared
|
||||||
|
|
||||||
alias Ecto.Adapters.SQL.Sandbox
|
|
||||||
alias Parrhesia.API.ACL
|
alias Parrhesia.API.ACL
|
||||||
alias Parrhesia.API.Events
|
alias Parrhesia.API.Events
|
||||||
alias Parrhesia.API.Identity
|
alias Parrhesia.API.Identity
|
||||||
alias Parrhesia.API.RequestContext
|
alias Parrhesia.API.RequestContext
|
||||||
alias Parrhesia.API.Sync
|
alias Parrhesia.API.Sync
|
||||||
alias Parrhesia.Protocol.EventValidator
|
alias Parrhesia.Protocol.EventValidator
|
||||||
alias Parrhesia.Repo
|
|
||||||
alias Parrhesia.Sync.Supervisor
|
alias Parrhesia.Sync.Supervisor
|
||||||
alias Parrhesia.TestSupport.SyncFakeRelay.Plug
|
alias Parrhesia.TestSupport.SyncFakeRelay.Plug
|
||||||
alias Parrhesia.TestSupport.SyncFakeRelay.Server
|
alias Parrhesia.TestSupport.SyncFakeRelay.Server
|
||||||
|
|
||||||
setup do
|
|
||||||
:ok = Sandbox.checkout(Repo)
|
|
||||||
Sandbox.mode(Repo, {:shared, self()})
|
|
||||||
|
|
||||||
on_exit(fn ->
|
|
||||||
Sandbox.mode(Repo, :manual)
|
|
||||||
end)
|
|
||||||
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
test "req_stream worker verifies remote identity, authenticates, syncs catch-up, streams live, and sync_now reruns catch-up" do
|
test "req_stream worker verifies remote identity, authenticates, syncs catch-up, streams live, and sync_now reruns catch-up" do
|
||||||
{:ok, %{pubkey: local_pubkey}} = Identity.ensure()
|
{:ok, %{pubkey: local_pubkey}} = Identity.ensure()
|
||||||
remote_pubkey = String.duplicate("b", 64)
|
remote_pubkey = String.duplicate("b", 64)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
defmodule Parrhesia.Tasks.ExpirationWorkerTest do
|
defmodule Parrhesia.Tasks.ExpirationWorkerTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false
|
||||||
|
|
||||||
alias Parrhesia.Tasks.ExpirationWorker
|
alias Parrhesia.Tasks.ExpirationWorker
|
||||||
alias Parrhesia.TestSupport.ExpirationStubEvents
|
alias Parrhesia.TestSupport.ExpirationStubEvents
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
defmodule Parrhesia.Tasks.PartitionRetentionWorkerTest do
|
defmodule Parrhesia.Tasks.PartitionRetentionWorkerTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false
|
||||||
|
|
||||||
alias Parrhesia.Tasks.PartitionRetentionWorker
|
alias Parrhesia.Tasks.PartitionRetentionWorker
|
||||||
alias Parrhesia.TestSupport.PartitionRetentionStubPartitions
|
alias Parrhesia.TestSupport.PartitionRetentionStubPartitions
|
||||||
|
|||||||
@@ -1,17 +1,10 @@
|
|||||||
defmodule Parrhesia.Web.ConformanceTest do
|
defmodule Parrhesia.Web.ConformanceTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false, sandbox: true
|
||||||
|
|
||||||
alias Ecto.Adapters.SQL.Sandbox
|
|
||||||
alias Parrhesia.Protocol.EventValidator
|
alias Parrhesia.Protocol.EventValidator
|
||||||
alias Parrhesia.Repo
|
|
||||||
alias Parrhesia.Storage
|
alias Parrhesia.Storage
|
||||||
alias Parrhesia.Web.Connection
|
alias Parrhesia.Web.Connection
|
||||||
|
|
||||||
setup do
|
|
||||||
:ok = Sandbox.checkout(Repo)
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
test "REQ -> EOSE emitted once and CLOSE emits CLOSED" do
|
test "REQ -> EOSE emitted once and CLOSE emits CLOSED" do
|
||||||
{:ok, state} = Connection.init(subscription_index: nil)
|
{:ok, state} = Connection.init(subscription_index: nil)
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,14 @@
|
|||||||
defmodule Parrhesia.Web.ConnectionTest do
|
defmodule Parrhesia.Web.ConnectionTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false, sandbox: true
|
||||||
|
|
||||||
alias Ecto.Adapters.SQL.Sandbox
|
|
||||||
alias Parrhesia.API.ACL
|
alias Parrhesia.API.ACL
|
||||||
alias Parrhesia.API.Events
|
alias Parrhesia.API.Events
|
||||||
alias Parrhesia.API.RequestContext
|
alias Parrhesia.API.RequestContext
|
||||||
alias Parrhesia.Negentropy.Engine
|
alias Parrhesia.Negentropy.Engine
|
||||||
alias Parrhesia.Negentropy.Message
|
alias Parrhesia.Negentropy.Message
|
||||||
alias Parrhesia.Protocol.EventValidator
|
alias Parrhesia.Protocol.EventValidator
|
||||||
alias Parrhesia.Repo
|
|
||||||
alias Parrhesia.Web.Connection
|
alias Parrhesia.Web.Connection
|
||||||
|
|
||||||
setup do
|
|
||||||
ensure_repo_started()
|
|
||||||
ensure_stream_runtime_started()
|
|
||||||
:ok = Sandbox.checkout(Repo)
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
test "REQ registers subscription, streams initial events and replies with EOSE" do
|
test "REQ registers subscription, streams initial events and replies with EOSE" do
|
||||||
state = connection_state()
|
state = connection_state()
|
||||||
|
|
||||||
@@ -876,26 +867,6 @@ defmodule Parrhesia.Web.ConnectionTest do
|
|||||||
state
|
state
|
||||||
end
|
end
|
||||||
|
|
||||||
defp ensure_stream_runtime_started do
|
|
||||||
if is_nil(Process.whereis(Parrhesia.API.Stream.Supervisor)) do
|
|
||||||
case start_supervised({Parrhesia.Subscriptions.Supervisor, []}) do
|
|
||||||
{:ok, _pid} -> :ok
|
|
||||||
{:error, {:already_started, _pid}} -> :ok
|
|
||||||
end
|
|
||||||
else
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp ensure_repo_started do
|
|
||||||
if is_nil(Process.whereis(Repo)) do
|
|
||||||
_ = start_supervised(Repo)
|
|
||||||
:ok
|
|
||||||
else
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp listener(overrides) do
|
defp listener(overrides) do
|
||||||
base = %{
|
base = %{
|
||||||
id: :test,
|
id: :test,
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
defmodule Parrhesia.Web.ProxyIpE2ETest do
|
defmodule Parrhesia.Web.ProxyIpE2ETest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false, sandbox: :shared
|
||||||
|
|
||||||
alias __MODULE__.TestClient
|
alias __MODULE__.TestClient
|
||||||
alias Ecto.Adapters.SQL.Sandbox
|
|
||||||
alias Parrhesia.Repo
|
|
||||||
|
|
||||||
setup_all do
|
setup_all do
|
||||||
{:ok, _apps} = Application.ensure_all_started(:websockex)
|
{:ok, _apps} = Application.ensure_all_started(:websockex)
|
||||||
@@ -11,14 +9,10 @@ defmodule Parrhesia.Web.ProxyIpE2ETest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
:ok = Sandbox.checkout(Repo)
|
|
||||||
Sandbox.mode(Repo, {:shared, self()})
|
|
||||||
|
|
||||||
previous_trusted_proxies = Application.get_env(:parrhesia, :trusted_proxies, [])
|
previous_trusted_proxies = Application.get_env(:parrhesia, :trusted_proxies, [])
|
||||||
|
|
||||||
on_exit(fn ->
|
on_exit(fn ->
|
||||||
Application.put_env(:parrhesia, :trusted_proxies, previous_trusted_proxies)
|
Application.put_env(:parrhesia, :trusted_proxies, previous_trusted_proxies)
|
||||||
Sandbox.mode(Repo, :manual)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
{:ok, port: free_port()}
|
{:ok, port: free_port()}
|
||||||
|
|||||||
@@ -1,21 +1,14 @@
|
|||||||
defmodule Parrhesia.Web.RouterTest do
|
defmodule Parrhesia.Web.RouterTest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false, sandbox: true
|
||||||
|
|
||||||
import Plug.Conn
|
import Plug.Conn
|
||||||
import Plug.Test
|
import Plug.Test
|
||||||
|
|
||||||
alias Ecto.Adapters.SQL.Sandbox
|
|
||||||
alias Parrhesia.API.Sync
|
alias Parrhesia.API.Sync
|
||||||
alias Parrhesia.Protocol.EventValidator
|
alias Parrhesia.Protocol.EventValidator
|
||||||
alias Parrhesia.Repo
|
|
||||||
alias Parrhesia.Web.Listener
|
alias Parrhesia.Web.Listener
|
||||||
alias Parrhesia.Web.Router
|
alias Parrhesia.Web.Router
|
||||||
|
|
||||||
setup do
|
|
||||||
:ok = Sandbox.checkout(Repo)
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
|
|
||||||
test "GET /health returns ok" do
|
test "GET /health returns ok" do
|
||||||
conn = conn(:get, "/health") |> Router.call([])
|
conn = conn(:get, "/health") |> Router.call([])
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,11 @@
|
|||||||
defmodule Parrhesia.Web.TLSE2ETest do
|
defmodule Parrhesia.Web.TLSE2ETest do
|
||||||
use ExUnit.Case, async: false
|
use Parrhesia.IntegrationCase, async: false, sandbox: :shared
|
||||||
|
|
||||||
alias Ecto.Adapters.SQL.Sandbox
|
|
||||||
alias Parrhesia.Repo
|
|
||||||
alias Parrhesia.Sync.Transport.WebSockexClient
|
alias Parrhesia.Sync.Transport.WebSockexClient
|
||||||
alias Parrhesia.TestSupport.TLSCerts
|
alias Parrhesia.TestSupport.TLSCerts
|
||||||
alias Parrhesia.Web.Endpoint
|
alias Parrhesia.Web.Endpoint
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
:ok = Sandbox.checkout(Repo)
|
|
||||||
Sandbox.mode(Repo, {:shared, self()})
|
|
||||||
|
|
||||||
tmp_dir =
|
tmp_dir =
|
||||||
Path.join(
|
Path.join(
|
||||||
System.tmp_dir!(),
|
System.tmp_dir!(),
|
||||||
@@ -20,7 +15,6 @@ defmodule Parrhesia.Web.TLSE2ETest do
|
|||||||
File.mkdir_p!(tmp_dir)
|
File.mkdir_p!(tmp_dir)
|
||||||
|
|
||||||
on_exit(fn ->
|
on_exit(fn ->
|
||||||
Sandbox.mode(Repo, :manual)
|
|
||||||
_ = File.rm_rf(tmp_dir)
|
_ = File.rm_rf(tmp_dir)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
43
test/support/integration_case.ex
Normal file
43
test/support/integration_case.ex
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
defmodule Parrhesia.IntegrationCase do
|
||||||
|
@moduledoc false
|
||||||
|
|
||||||
|
use ExUnit.CaseTemplate
|
||||||
|
|
||||||
|
alias Ecto.Adapters.SQL.Sandbox
|
||||||
|
alias ExUnit.Case
|
||||||
|
alias Parrhesia.Repo
|
||||||
|
alias Parrhesia.TestSupport.Runtime
|
||||||
|
|
||||||
|
using opts do
|
||||||
|
quote bind_quoted: [opts: opts] do
|
||||||
|
use Case, async: Keyword.get(opts, :async, false)
|
||||||
|
|
||||||
|
alias Ecto.Adapters.SQL.Sandbox
|
||||||
|
alias Parrhesia.Repo
|
||||||
|
|
||||||
|
@moduletag parrhesia_sandbox: Keyword.get(opts, :sandbox, false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
setup tags do
|
||||||
|
Runtime.ensure_started!()
|
||||||
|
|
||||||
|
case tags[:parrhesia_sandbox] do
|
||||||
|
false ->
|
||||||
|
:ok
|
||||||
|
|
||||||
|
true ->
|
||||||
|
:ok = Sandbox.checkout(Repo)
|
||||||
|
|
||||||
|
:shared ->
|
||||||
|
:ok = Sandbox.checkout(Repo)
|
||||||
|
Sandbox.mode(Repo, {:shared, self()})
|
||||||
|
|
||||||
|
on_exit(fn ->
|
||||||
|
Sandbox.mode(Repo, :manual)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
end
|
||||||
34
test/support/runtime.ex
Normal file
34
test/support/runtime.ex
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
defmodule Parrhesia.TestSupport.Runtime do
|
||||||
|
@moduledoc false
|
||||||
|
|
||||||
|
@required_processes [
|
||||||
|
Parrhesia.Supervisor,
|
||||||
|
Parrhesia.Config,
|
||||||
|
Parrhesia.Repo,
|
||||||
|
Parrhesia.Subscriptions.Supervisor,
|
||||||
|
Parrhesia.Web.Endpoint
|
||||||
|
]
|
||||||
|
|
||||||
|
def ensure_started! do
|
||||||
|
if healthy?() do
|
||||||
|
:ok
|
||||||
|
else
|
||||||
|
restart!()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp healthy? do
|
||||||
|
Enum.all?(@required_processes, &is_pid(Process.whereis(&1)))
|
||||||
|
end
|
||||||
|
|
||||||
|
defp restart! do
|
||||||
|
case Application.stop(:parrhesia) do
|
||||||
|
:ok -> :ok
|
||||||
|
{:error, {:not_started, :parrhesia}} -> :ok
|
||||||
|
{:error, {:not_started, _app}} -> :ok
|
||||||
|
end
|
||||||
|
|
||||||
|
{:ok, _apps} = Application.ensure_all_started(:parrhesia)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -5,6 +5,4 @@ exclude_tags =
|
|||||||
[:nak_e2e]
|
[:nak_e2e]
|
||||||
end
|
end
|
||||||
|
|
||||||
{:ok, _apps} = Application.ensure_all_started(:parrhesia)
|
|
||||||
|
|
||||||
ExUnit.start(exclude: exclude_tags)
|
ExUnit.start(exclude: exclude_tags)
|
||||||
|
|||||||
Reference in New Issue
Block a user