Starting multiple named nodes locally for ExUnit tests

My app is distributed using @bitwalker’s libcluster and swarm libraries. I’m currently trying to write tests for specific parts of my app that hook into these libraries and am unable to due to the fact that I need to have multiple named nodes spun up locally in order to even function. I’ve tried using the test code in distillery/libcluster/swarm as examples in order to pull this off but have been unsuccessful. Furthermore I’m not entirely sure if the node’s creation should be in the test_helper.ex or in the setup_all. I’ve tried putting Node.start()'s and :slave.start_link's to no avail. Additionally since my app uses Phoenix, I think I will need to have multiple endpoint configs for test? Any and all help, tips, examples is appreciated. Thank you.

2 Likes

You can see an example in https://github.com/ericentin/repg2

It has tests with another node. Maybe you can adapt it to your needs.

1 Like

I’ve tried my hand at this using the clusters strategy that swarm and firenest employ, but to no avail:

https://gist.github.com/beardedeagle/df0e56622b564871b409057b89fd0745

1 Like

…and then I found this: https://github.com/sschneider1207/distributed_test. Let’s see if I can get it to work.

You could look at what Phoenix itself does when testing PubSub:

2 Likes

I’ve updated the gist again with the work @bitwalker and I have put into it:
https://gist.github.com/beardedeagle/df0e56622b564871b409057b89fd0745
Still not working, but progress is being made.

Hey @beardedeagle, you should look into https://github.com/wooga/flock.

It might give you some hints how to do setup the tests.
Good luck!

1 Like

Thanks for everyone’s help and suggestions. @bitwalker and I were able to get this running using the following cluster_case code: https://gist.github.com/beardedeagle/dc72f25fb561780f902d5dbf354a582d

4 Likes