whitfin / local-cluster

Easy local cluster creation for Elixir to aid in unit testing
MIT License
226 stars 30 forks source link

Start the environment using Mix. #5

Closed xadhoom closed 4 years ago

xadhoom commented 5 years ago

When starting the nodes the current implementation does not take in account applications deps, which results in application started out of order and configurations wrongly merged. Using Mix allow to start in the correct order with the very same environment that the developer expects.

whitfin commented 5 years ago

@xadhoom hi! Before I think about merging this, a couple of questions;

  1. Was this causing any actual issues before this change?
  2. Is Mix.CLI actually a "public" API? I see nothing about it in documentation, and so I'm not sure about relying on it.
xadhoom commented 5 years ago
  1. Was this causing any actual issues before this change?

Yes, I discovered it on a project within an umbrella, where umbrella apps have a specific startup order obtained using in umbrella deps. And each app configures it own deps, The startup sequence from local_cluster does not match the deps tree, leading into applications started with a "default" config.

Example: umbrella with 2 apps. :app_b depends on :app_a The startup sequence is (according to deps):

The config is merged following deps: app_b can set app_a config values because is dependant of it.

When starting following loaded apps list, app_a may be started before app_b (which is correct in this scenario), but since Application.put_env for app_b is not yet called, app_a starts with a different config from what app_b wants to apply on app_a.

This is exactly what we verified, a dep is configured with its "default" config and when the dependant is started, finds its dep running with a different config that expected.

  1. Is Mix.CLI actually a "public" API? I see nothing about it in documentation, and so I'm not sure about relying on it.

The Mix.CLI module actually has @moduledoc set to false, so strictly speaking, is not a pubblic API. On the other hand it's main method is public and documented. Also is the very same invocation that the mix script do when you call iex -S mix. I've also checked, and this API never changed from elixir 1.0 till now.

xadhoom commented 5 years ago

This may also be solved by merging all the configurations following the "inverse" dep tree, but is not trivial, and mix already do that for us, so why not use it :)

xadhoom commented 5 years ago

Side note: I've double checked from elixir cli, and the Mix.CLI.main is reachable (means that autocomplete works) and documented (means that h Mix.CLI.main returns the doc). So while the module itself is hidden, the main api isn't so can be considered public?

whitfin commented 4 years ago

So... I looked this over and I believe it can be resolved by #15, which has been merged. Want to try on latest master?

I'm going to close for now, but feel free to re-open if you think it should be!