Skip to content

Commit 80cf009

Browse files
authored
fix(tests): unlink component setups to avoid teardown races (#3302)
When running `mix test test/electric/shape_cache_test.exs` in particular, there were a lot of error-level logs on consumer failing to register itself with a shape status. It was happening after the test passed. I found that this happens because components we're starting in `setup` part of the test were using `start_link_supervised` instead of `start_supervised`, which caused them to be shut down all together when the test completed, instead of being shut down in correct supervision order as they would in a real system. This PR replaces all `start_link_supervised` in the component setup.
1 parent c3e2582 commit 80cf009

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

packages/sync-service/test/support/component_setup.ex

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ defmodule Support.ComponentSetup do
4545

4646
def with_stack_id_from_test(ctx) do
4747
stack_id = full_test_name(ctx)
48-
registry = start_link_supervised!({Electric.ProcessRegistry, stack_id: stack_id})
48+
registry = start_supervised!({Electric.ProcessRegistry, stack_id: stack_id})
4949
start_supervised!({Electric.StackConfig, stack_id: stack_id})
5050
%{stack_id: stack_id, process_registry: registry}
5151
end
5252

5353
def with_registry(ctx) do
5454
registry_name = :"#{inspect(Registry.ShapeChanges)}:#{ctx.stack_id}"
55-
start_link_supervised!({Registry, keys: :duplicate, name: registry_name})
55+
start_supervised!({Registry, keys: :duplicate, name: registry_name})
5656

5757
%{registry: registry_name}
5858
end
@@ -74,7 +74,7 @@ defmodule Support.ComponentSetup do
7474
"electric-trash-#{System.monotonic_time()}-#{System.unique_integer([:positive, :monotonic])}"
7575
)
7676

77-
start_link_supervised!(
77+
start_supervised!(
7878
{Electric.AsyncDeleter,
7979
stack_id: ctx.stack_id, storage_dir: storage_dir, cleanup_interval_ms: 0}
8080
)
@@ -123,14 +123,14 @@ defmodule Support.ComponentSetup do
123123
end
124124

125125
def with_shape_cleaner(ctx) do
126-
start_link_supervised!({Electric.ShapeCache.ShapeCleaner, stack_id: ctx.stack_id})
126+
start_supervised!({Electric.ShapeCache.ShapeCleaner, stack_id: ctx.stack_id})
127127
:ok
128128
end
129129

130130
def with_publication_manager(ctx) do
131131
server = :"publication_manager_#{full_test_name(ctx)}"
132132

133-
start_link_supervised!(%{
133+
start_supervised!(%{
134134
id: server,
135135
start: {
136136
Electric.Replication.PublicationManager,
@@ -164,7 +164,7 @@ defmodule Support.ComponentSetup do
164164
end
165165

166166
def with_shape_status(ctx) do
167-
start_link_supervised!(%{
167+
start_supervised!(%{
168168
id: "shape_status_owner",
169169
start:
170170
{Electric.ShapeCache.ShapeStatusOwner, :start_link,
@@ -184,7 +184,7 @@ defmodule Support.ComponentSetup do
184184
server = :"shape_cache_#{full_test_name(ctx)}"
185185
consumer_supervisor = :"consumer_supervisor_#{full_test_name(ctx)}"
186186

187-
start_link_supervised!(
187+
start_supervised!(
188188
{Task.Supervisor,
189189
name: Electric.ProcessRegistry.name(ctx.stack_id, Electric.StackTaskSupervisor)}
190190
|> Supervisor.child_spec(id: "shape_task_supervisor")
@@ -209,9 +209,9 @@ defmodule Support.ComponentSetup do
209209
{Electric.Shapes.DynamicConsumerSupervisor,
210210
[name: consumer_supervisor, stack_id: ctx.stack_id]}
211211
|> Supervisor.child_spec(id: consumer_supervisor, restart: :temporary)
212-
|> start_link_supervised!()
212+
|> start_supervised!()
213213

214-
start_link_supervised!(%{
214+
start_supervised!(%{
215215
id: start_opts[:name],
216216
start: {ShapeCache, :start_link, [start_opts]},
217217
restart: :temporary
@@ -240,7 +240,7 @@ defmodule Support.ComponentSetup do
240240
def with_shape_log_collector(ctx) do
241241
name = ShapeLogCollector.name(ctx.stack_id)
242242

243-
start_link_supervised!(
243+
start_supervised!(
244244
{ShapeLogCollector,
245245
[stack_id: ctx.stack_id, inspector: ctx.inspector, persistent_kv: ctx.persistent_kv]},
246246
id: name,
@@ -270,7 +270,7 @@ defmodule Support.ComponentSetup do
270270

271271
def with_inspector(ctx) do
272272
server =
273-
start_link_supervised!(
273+
start_supervised!(
274274
{EtsInspector,
275275
stack_id: ctx.stack_id, pool: ctx.db_conn, persistent_kv: ctx.persistent_kv}
276276
)
@@ -285,7 +285,7 @@ defmodule Support.ComponentSetup do
285285
end
286286

287287
def with_status_monitor(ctx) do
288-
start_link_supervised!({Electric.StatusMonitor, stack_id: ctx.stack_id})
288+
start_supervised!({Electric.StatusMonitor, stack_id: ctx.stack_id})
289289
%{}
290290
end
291291

@@ -321,7 +321,7 @@ defmodule Support.ComponentSetup do
321321
publication_manager
322322
end)
323323

324-
start_link_supervised!(
324+
start_supervised!(
325325
{Electric.Shapes.Monitor,
326326
Keyword.merge(monitor_config(ctx),
327327
stack_id: ctx.stack_id,

0 commit comments

Comments
 (0)