Skip to content

Commit 27af6b7

Browse files
fix Phoenix.PubSub test setup and update Elixir to 1.18
1 parent 8f2da42 commit 27af6b7

7 files changed

Lines changed: 51 additions & 28 deletions

File tree

apps/kafkaesque_client/mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule KafkaesqueClient.MixProject do
99
config_path: "../../config/config.exs",
1010
deps_path: "../../deps",
1111
lockfile: "../../mix.lock",
12-
elixir: "~> 1.17",
12+
elixir: "~> 1.18",
1313
elixirc_paths: elixirc_paths(Mix.env()),
1414
start_permanent: Mix.env() == :prod,
1515
aliases: aliases(),

apps/kafkaesque_core/mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule KafkaesqueCore.MixProject do
99
config_path: "../../config/config.exs",
1010
deps_path: "../../deps",
1111
lockfile: "../../mix.lock",
12-
elixir: "~> 1.17",
12+
elixir: "~> 1.18",
1313
elixirc_paths: elixirc_paths(Mix.env()),
1414
start_permanent: Mix.env() == :prod,
1515
aliases: aliases(),

apps/kafkaesque_core/test/pipeline/produce_broadway_test.exs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ defmodule Kafkaesque.Pipeline.ProduceBroadwayTest do
6767
max_queue_size: 100
6868
)
6969

70-
{:ok, _pid} =
71-
ProduceBroadway.start_link(
72-
topic: @test_topic,
73-
partition: @test_partition,
74-
batch_size: 5,
75-
batch_timeout: 1
76-
)
70+
case ProduceBroadway.start_link(
71+
topic: @test_topic,
72+
partition: @test_partition,
73+
batch_size: 5,
74+
batch_timeout: 1
75+
) do
76+
{:ok, _pid} -> :ok
77+
{:error, {:already_started, _pid}} -> :ok
78+
end
7779

7880
:ok
7981
end
@@ -266,13 +268,15 @@ defmodule Kafkaesque.Pipeline.ProduceBroadwayTest do
266268
max_queue_size: 100
267269
)
268270

269-
{:ok, _pid} =
270-
ProduceBroadway.start_link(
271-
topic: @test_topic,
272-
partition: @test_partition,
273-
batch_size: 5,
274-
batch_timeout: 1
275-
)
271+
case ProduceBroadway.start_link(
272+
topic: @test_topic,
273+
partition: @test_partition,
274+
batch_size: 5,
275+
batch_timeout: 1
276+
) do
277+
{:ok, _pid} -> :ok
278+
{:error, {:already_started, _pid}} -> :ok
279+
end
276280

277281
:ok
278282
end

apps/kafkaesque_core/test/support/test_case.ex

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

apps/kafkaesque_core/test/topic/supervisor_test.exs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ defmodule Kafkaesque.Topic.SupervisorTest do
1414
Application.put_env(:kafkaesque_core, :offsets_dir, Path.join(test_dir, "offsets"))
1515

1616
# Start the topic supervisor if not already started
17-
case TopicSupervisor.start_link([]) do
18-
{:ok, pid} -> {:ok, pid}
19-
{:error, {:already_started, pid}} -> {:ok, pid}
17+
case Process.whereis(TopicSupervisor) do
18+
nil ->
19+
case TopicSupervisor.start_link([]) do
20+
{:ok, pid} -> {:ok, pid}
21+
{:error, {:already_started, pid}} -> {:ok, pid}
22+
end
23+
pid ->
24+
{:ok, pid}
2025
end
2126

2227
on_exit(fn ->

apps/kafkaesque_dashboard/mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule KafkaesqueDashboard.MixProject do
99
config_path: "../../config/config.exs",
1010
deps_path: "../../deps",
1111
lockfile: "../../mix.lock",
12-
elixir: "~> 1.17",
12+
elixir: "~> 1.18",
1313
elixirc_paths: elixirc_paths(Mix.env()),
1414
start_permanent: Mix.env() == :prod,
1515
aliases: aliases(),

apps/kafkaesque_server/mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule KafkaesqueServer.MixProject do
99
config_path: "../../config/config.exs",
1010
deps_path: "../../deps",
1111
lockfile: "../../mix.lock",
12-
elixir: "~> 1.17",
12+
elixir: "~> 1.18",
1313
elixirc_paths: elixirc_paths(Mix.env()),
1414
start_permanent: Mix.env() == :prod,
1515
aliases: aliases(),

0 commit comments

Comments
 (0)