Parent upgrade 0.9 -> 0.12 errors in tests

I upgraded a project using Parent from 0.9 to 0.12.

I translated the functions to the new format and that works as expected now. However, now in the tests, when starting supervised the supervisor doesn’t want to let the child die at the end of the test so it is throwing an error. The tests still pass but it’s polluting the output of the tests and making them run a lot slower. Nothing else has changed in the tests apart from upgrading Parent.

An example error of which there are many.

[16:18:36.727] [error] module=supervisor function=do_terminate/2
Child "6f4e8c3c-c830-4d51-8b2e-c45188831a1f" of Supervisor #PID<0.1128.0> (Supervisor.Default) shut down abnormally
** (exit) killed
Pid: #PID<0.1130.0>
Start Call: ....
Restart: :permanent
Shutdown: 5000
Type: :worker

Any ideas how to get rid of these errors?

@sasajuric Any assistance would be appreciated!

It’s possibly caused by the breaking change in 0.11. From the related changelog section:

Children are by default permanent and non-ephemeral, which changes the behaviour compared to previous versions. To retain the previous behaviour, include restart: :temporary, ephemeral?: true in a childspec of every child.

1 Like

Yes. I have that change implemented.
For example:

{:ok, pid} =
      Parent.start_child(
        Parent.child_spec(%{
          start: {TimedQueue, :start_link, [Queue, %{from: self()}]},
          id: "queue",
          ephemeral?: true,
          restart: :temporary
        })
      )

Is there some other supervisor or child_spec that could be effecting it?

Not that I can think of. Could you create a minimal reproduction example in a standalone repo?

I’m still trying to track it down. It looks like the child in the context of the test is getting set to restart: :permanent.

The pids match so this looks like it’s not getting set properly.

child_spec: %{
  binds_to: [],
  ephemeral?: true,
  id: "websocket",
  max_restarts: :infinity,
  max_seconds: 5000,
  meta: nil,
  modules: [Mock.Websocket],
  restart: :temporary,
  shutdown: 5000,
  shutdown_group: nil,
  start: {Mock.Module, :start_link,
   [
     %{
       service_pid: #PID<0.1151.0>,
       url: "wss://example.com/ws/22AF3JIOQBDSOJCZ/c/1618308666665"
     }
   ]},
  timeout: :infinity,
  type: :worker
}
start_child: {:ok, #PID<0.1151.0>}
[12:11:16.667] [error] module=supervisor function=do_terminate/2
Child "c82bc7c7-2b39-4fb2-be5d-d5050dc1a3da" of Supervisor #PID<0.1149.0> (Supervisor.Default) shut down abnormally
** (exit) killed
Pid: #PID<0.1151.0>
Start Call: Module.start_link([:"747d7610-191f-4e69-bab9-d357e5ca4afdtest_server", ...])
Restart: :permanent
Shutdown: 5000
Type: :worker

We solved it. It turns out we were doing some things in our tests we shouldn’t have been doing.

Bad:


Mock.Websocket
|> expect(:start_link, 4, fn _ ->{:ok, self()} end)

Good:


Mock.Websocket 
|> expect(:start_link, 4, fn _ -> Agent.start_link(fn -> true end) end)

The websocket is the child.

Does this make sense in light of how Parent operates?

1 Like