Starting multiple named nodes locally for ExUnit tests

distributed-systems
phoenix
testing
exunit
Tags: #<Tag:0x00007f8e9fd31488> #<Tag:0x00007f8e9fd31348> #<Tag:0x00007f8e9fd31208> #<Tag:0x00007f8e9fd310c8>

#1

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

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.


#3

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


#4

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


#5

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


#6

I’ve updated the gist again with the work @bitwalker and I have put into it:


Still not working, but progress is being made.


#7

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!


#8

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