Hi,
I’m a newbie to Elixir and OTP and trying to learn them by building a small testing tool. It is a tool that regularly make some REST call to my service to check their SLA ( in this case, response time). Here is the supervision tree that I come up with.
Quick summary on the roles of each process.
-
Control center is the brain and it will spawn a synthesizer for each system that I want to test
-
Synthesizer is responsible for scheduling new Test (by messaging Tester Supervisor to spawn new Tester process) based on some schedule (for example one test per minutes)
-
Tester Supervisor is responsible for spawning new tester and manage their lifecycle
-
Tester is the process that will make some rest calls and measure the response time.
I ran into couple things that I’m not sure and would be great if someone can give me some advice.
-
Am I structuring the process right? I am not sure when to use Supervisor and when to use GenServer and this is what I come up with the best of my knowledge.
-
From my understanding, I need to explicitly make a call to
Supervisor.start_child/2
when I want to spawn a new child supervised usingsimple_one_to_one
strategy. But where should I call this? From different online tutorials or docs, I can see that there’re different approaches. For example, some will suggest adding a new client API in the supervisor, something likecreate_child
and in that call, invokeSupervisor.start_child/2
. Others will add a new client API in the child, likecreate
, and invokeSupervisor.start_child/2
and refer to the Supervisor using Module name. Is there a convention in Elixir for this? or it’s really up to the implementer? If it’s the later one, anyone can share some pros and cons of the two approaches? -
How can I unit test those process (Control Center, Synthesizer, etc)? They are all wired together and how can I test each of them individually? ( for example, if I write a test to verify synthesizer is messaging Tester Supervisor correctly, it will involve every process, from Control Center coz it spawn Synthesizer, to Tester process coz I want to make sure new Tester processes are spawned correctly).
Thanks for reading this long posts and would be great if someone can give me some advice