sschneider

sschneider

Distributed Tests Mix Task

Lately I’ve been working on more distributed applications, and I was struggling to come up with an easy way of testing them with ExUnit. I looked how Phoenix PubSub does theirs and it seemed fairly simple so I pulled it out into a mix task. I figured other people might have a use for this as well so I published it on hex with the name distributed_test.

It’s pretty simple to use, just run mix test.distributed [--count N] and a clustered environment with your app loaded on every node will be started before your tests are ran.

There’s also a helper module in it DistributedEnviroment that has a start/1 and stop/0 function you can use when developing to quickly start up N number of nodes with your application loaded.

There’s a small gotcha with this in that if you define code in your test_helper.exs, it will only be loaded on the master node, so you’ll want to do something like this in your helper file:

defmodule Utils do
  @module (quote do
    defmodule Foo do
      # ...
    end
  end)

  def load_foo() do
    Code.eval_quoted(@module)
    Node.list()
    |> Enum.each(&:rpc.block_call(&1, Code, :eval_quoted, [@module]))
  end
end

and call Utils.load_foo() in your test/in the helper if you need code loaded on all nodes.

Where Next?

Popular in Announcing Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36689 110
New
maltoe
Hello! Came here to announce ChromicPDF, a pet project PDF generator I’ve been working on for the past few months. Why another PDF gener...
New
Qqwy
TypeCheck: Fast and flexible runtime type-checking for your Elixir projects. Core ideas Type- and function specifications are const...
336 14713 100
New
kevinlang
Hey all, We have made an Ecto3 Adapter for SQLite3, ecto_sqlite3! We have successfully on-boarded the full suite of integration tests (...
New
dominicletz
Hi, I thought I had posted my library before but seems I hadn’t. The project is still in early stages but it’s growing and so I think it...
New
tfwright
After working on it for a couple of months and using it in production for most of that time, today I’ve released LiveAdmin, a LiveView ba...
New
wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
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...
3271 130579 1222
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54092 488
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49134 226
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New

We're in Beta

About us Mission Statement