@@ -20,7 +20,10 @@ defmodule Kafkaesque.TestCase do
2020 setup do
2121 # Start required registries and services
2222 ensure_registry_started ( )
23- ensure_pubsub_started ( )
23+ # Only start PubSub if the application isn't already managing it
24+ unless Application . started_applications ( ) |> Enum . any? ( fn { app , _ , _ } -> app == :kafkaesque_core end ) do
25+ ensure_pubsub_started ( )
26+ end
2427 ensure_telemetry_started ( )
2528
2629 :ok
@@ -40,12 +43,23 @@ defmodule Kafkaesque.TestCase do
4043 Ensures PubSub is started.
4144 """
4245 def ensure_pubsub_started do
43- case Phoenix.PubSub.Supervisor . start_link (
44- name: Kafkaesque.PubSub ,
45- adapter: Phoenix.PubSub.PG2
46- ) do
47- { :ok , _ } -> :ok
48- { :error , { :already_started , _ } } -> :ok
46+ # Check if PubSub is already running
47+ case Process . whereis ( Kafkaesque.PubSub ) do
48+ nil ->
49+ # Not running, start it
50+ children = [
51+ { Phoenix.PubSub , name: Kafkaesque.PubSub }
52+ ]
53+
54+ case Supervisor . start_link ( children , strategy: :one_for_one , name: KafkaesqueTestPubSub ) do
55+ { :ok , _ } -> :ok
56+ { :error , { :already_started , _ } } -> :ok
57+ { :error , { :shutdown , { :failed_to_start_child , Phoenix.PubSub , { :already_started , _ } } } } -> :ok
58+ end
59+
60+ _pid ->
61+ # Already running
62+ :ok
4963 end
5064 end
5165
0 commit comments