Skip to content

Commit a225467

Browse files
committed
test: enable async on RepoCase tests using start_enactment
Forward `$callers` from the calling process into the spawned Enactment GenServer so Ecto's sandbox ownership lookup can find the test's connection. This unblocks `async: true` for the 11 test files that exercise a real Enactment via `start_enactment/2`. Also call `Sandbox.allow/3` in the helper as belt-and-suspenders for any future descendant processes. The `$callers` pattern is the documented Elixir 1.17+ approach for GenServers spawned from test processes. In production the chain is empty and the change is a no-op. `lifespan_test.exs` and `default_logger_test.exs` remain synchronous because they mutate Application env / Logger config / telemetry handlers keyed by stable handler ids. Snapshot-debounce telemetry handler in `enactment_test.exs` is narrowed to filter by `metadata.enactment_id` so concurrent enactments don't pollute its burst measurement. Wall-clock test time drops ~30-45% on the local machine.
1 parent f47ae41 commit a225467

13 files changed

Lines changed: 23 additions & 16 deletions

lib/coloured_flow/runner/enactment/enactment.ex

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ defmodule ColouredFlow.Runner.Enactment do
9696
@spec start_link(options()) :: GenServer.on_start()
9797
def start_link(options) do
9898
enactment_id = Keyword.fetch!(options, :enactment_id)
99+
# Forward `$callers` from the calling process so collaborating processes
100+
# (e.g., Ecto.Adapters.SQL.Sandbox-aware tests) can be tracked. See
101+
# `ExUnit.Callbacks.start_supervised/2` for the recommended pattern.
102+
options = Keyword.put_new(options, :"$callers", Process.get(:"$callers", []))
99103

100104
GenServer.start_link(
101105
__MODULE__,
@@ -107,10 +111,13 @@ defmodule ColouredFlow.Runner.Enactment do
107111

108112
@impl GenServer
109113
def init(options) do
110-
state =
111-
__MODULE__
112-
|> struct(options)
113-
|> Map.put(:hibernate_after, Lifespan.hibernate_after_from_options(options))
114+
{callers, options} = Keyword.pop(options, :"$callers", [])
115+
Process.put(:"$callers", callers)
116+
117+
options =
118+
Keyword.put(options, :hibernate_after, Lifespan.hibernate_after_from_options(options))
119+
120+
state = struct(__MODULE__, options)
114121

115122
{:ok, state, {:continue, :populate_state}}
116123
end

test/coloured_flow/runner/enactment/enactment_termination_and_exception_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule ColouredFlow.Runner.Enactment.EnactmentTerminationAndExceptionTest do
2-
use ColouredFlow.RepoCase
2+
use ColouredFlow.RepoCase, async: true
33
use ColouredFlow.RunnerHelpers
44

55
import ColouredFlow.MultiSet, only: :sigils

test/coloured_flow/runner/enactment/enactment_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule ColouredFlow.Runner.EnactmentTest do
2-
use ColouredFlow.RepoCase
2+
use ColouredFlow.RepoCase, async: true
33
use ColouredFlow.RunnerHelpers
44

55
alias ColouredFlow.Enactment.BindingElement

test/coloured_flow/runner/enactment/integration_tests/constants_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule ColouredFlow.Runner.Enactment.IntegrationTests.ConstantsTest do
2-
use ColouredFlow.RepoCase
2+
use ColouredFlow.RepoCase, async: true
33
use ColouredFlow.RunnerHelpers
44

55
alias ColouredFlow.Enactment.BindingElement

test/coloured_flow/runner/enactment/integration_tests/pattern_match_on_complex_tokens_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule ColouredFlow.Runner.Enactment.IntegrationTests.PatternMatchOnComplexTokensTest do
2-
use ColouredFlow.RepoCase
2+
use ColouredFlow.RepoCase, async: true
33
use ColouredFlow.RunnerHelpers
44

55
alias ColouredFlow.Enactment.BindingElement

test/coloured_flow/runner/enactment/integration_tests/reuse_workitems_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule ColouredFlow.Runner.Enactment.IntegrationTests.ReuseWorkitemsTest do
2-
use ColouredFlow.RepoCase
2+
use ColouredFlow.RepoCase, async: true
33
use ColouredFlow.RunnerHelpers
44

55
alias ColouredFlow.Enactment.BindingElement

test/coloured_flow/runner/enactment/integration_tests/transition_without_input_places_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule ColouredFlow.Runner.Enactment.IntegrationTests.TransitionWithoutInputPlacesTest do
2-
use ColouredFlow.RepoCase
2+
use ColouredFlow.RepoCase, async: true
33
use ColouredFlow.RunnerHelpers
44

55
alias ColouredFlow.Enactment.BindingElement

test/coloured_flow/runner/enactment/integration_tests/transition_without_output_places_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule ColouredFlow.Runner.Enactment.IntegrationTests.TransitionWithoutOutputPlacesTest do
2-
use ColouredFlow.RepoCase
2+
use ColouredFlow.RepoCase, async: true
33
use ColouredFlow.RunnerHelpers
44

55
alias ColouredFlow.Enactment.BindingElement

test/coloured_flow/runner/enactment/integration_tests/transition_without_token_consumed_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule ColouredFlow.Runner.Enactment.IntegrationTests.TransitionWithoutTokenConsumedTest do
2-
use ColouredFlow.RepoCase
2+
use ColouredFlow.RepoCase, async: true
33
use ColouredFlow.RunnerHelpers
44

55
alias ColouredFlow.Enactment.BindingElement

test/coloured_flow/runner/enactment/integration_tests/transition_without_token_produced_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule ColouredFlow.Runner.Enactment.IntegrationTests.TransitionWithoutTokenProducedTest do
2-
use ColouredFlow.RepoCase
2+
use ColouredFlow.RepoCase, async: true
33
use ColouredFlow.RunnerHelpers
44

55
alias ColouredFlow.Enactment.BindingElement

0 commit comments

Comments
 (0)