Siscia
Siscia

Reputation: 1481

Elixir, test supervisor restart policy

I am writing an OTP application with a supervisor tree.

The main supervisor supervise two process a worker, QueueAddress, and another supervisor, QueueManager, with strategy one_for_one

QueueManager supervise a bunch of little Queues, with strategy simple_one_for_one, every time a new queue is started, its basic information are saved into the QueueAddress.

If a queue is killed, it is restarted correctly.

Now I want to test what happen if the supervisor QueueManager is killed.

However if a simply send a message Process.exit(QueueManager, :normal), or Process.exit(QueueManager, :shutdown) nothing happen, the PID of the QueueManager doesn't change nor the PIDs of the little queue that are supervised.

If I send a message Process.exit(QueueManager, :kill) the whole application gets down.

How can I test, what happen if QueueManager gets killed ?

Below the image of the OTP tree, I want to kill Elixir.QueueManager

The OTP tree

Upvotes: 4

Views: 677

Answers (1)

Siscia
Siscia

Reputation: 1481

It was pretty simple...

If you want to terminate the supervisor A, supervised by B you could do something like:

Supervisor.terminate_child B, A

If you want to bring back to life the supervisor A, still supervised by B you can do:

Supervisor.restart_child B, A

Upvotes: 2

Related Questions