archethic-foundation / archethic-foundation/archethic-node

make sure processes exit properly when tests terminate

Open
#719 0 comments 0 reactions 0 assignees View on GitHub
bug enhancements testing
Dominant language
Elixir
Stars
82
Forks
24
PR merge metrics
No merged PRs in 30d

Description

### Describe the problem you discovered

in test environment we have errors like
`[error] GenStateMachine Archethic.SharedSecrets.NodeRenewalScheduler terminating
** (Mox.UnexpectedCallError) no expectation defined for MockCrypto.node_shared_secrets_public_key/1 in process #PID<0.28092.0> with args [1]
(mox 1.0.2) lib/mox.ex:795: Mox.__dispatch__/4
(archethic 0.26.0) lib/archethic/shared_secrets/node_renewal.ex:30: Archethic.SharedSecrets.NodeRenewal.next_address/1
(archethic 0.26.0) lib/archethic/shared_secrets/node_renewal_scheduler.ex:109: Archethic.SharedSecrets.NodeRenewalScheduler.handle_event/4`

this is because the test finish but the genservers / processes are still running and they can't find the Mock.

### Describe the solution you'd like

We can leverage ExUnit callbacks like for example [on_exit](https://hexdocs.pm/ex_unit/main/ExUnit.Callbacks.html#on_exit/2), or even better start the required processes in supervised mode using [start_supervised](https://hexdocs.pm/ex_unit/main/ExUnit.Callbacks.html#start_supervised/2) and stop them properly using[ stop_supervised](https://hexdocs.pm/ex_unit/main/ExUnit.Callbacks.html#stop_supervised/1).

Contributor guide

Open the contributing guide

Research direction

Start by locating the tests that launch Archethic.SharedSecrets.NodeRenewalScheduler, then read lib/archethic/shared_secrets/node_renewal.ex and node_renewal_scheduler.ex around the reported calls. Check the ExUnit on_exit, start_supervised, and stop_supervised callbacks as possible lifecycle points. Done means the processes stop before test mocks are torn down and the reported Mox errors no longer occur.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.