BBQPupper

BBQPupper

How do you write unit tests for interactions between nodes?

Right now I am writing an Elixir application that is meant to be run in multiple nodes. When doing manual testing I run the application in different iex sessions using “iex --sname a@localhost -S mix” and call other nodes’ GenServers (for example one named Server) using “GenServer.call({Server, :b@localhost},{:write,1,2}).” This works for now but is tedious. I would like to write unit tests to automate this process, but can’t find any information on how to. What is the best way to get about doing this?

Most Liked

bitwalker

bitwalker

Leader

There are some pain points with :slave, which is ultimately why I wrote ex_unit_clustered_case - for simple cases, it works fine, a few of my libraries were basically built around testing via :slave; but for more complex applications the challenges start to become really noticeable.

The biggest thing you run into is realizing that just spinning up a few nodes isn’t enough - you generally want to test a lot of scenarios, and in a clustered application many of those scenarios will clobber other tests. This means you need to orchestrate clusters, not just nodes. Another problem is that you can get into situations where you have started nodes that don’t die when your tests fail, leaking beam processes. You have to have a mini framework built just to handle things like initializing nodes with different initial states for tests, etc.

Ultimately rebuilding all of that again and again is why I ended up throwing a library together. Ideally something would be baked into Elixir for this, but it’s definitely a lower priority in comparison to other things going on; in the meantime, let me know if my library covers your use cases, I’d like to make it a general solution to the problem

arjan

arjan

Check out https://github.com/bitwalker/ex_unit_clustered_case by @bitwalker. It’s fairly new but allows you to easily test multi node scenario’s.

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement