theburningmonk
theburningmonk

Reputation: 16051

Examples of using Eunit to test clustered application

I find the documentation on Eunit lacking, with regards to how to test a multi-node application. I found this example, but sadly when I run:

cluster_test_() ->  
    {node, foo,
     fun (Node) ->
        [?_assertEqual(pong, net_adm:ping(Node))]
     end
    }.

I get:

undefined
*** context setup failed ***
** in function slave:start/5 (slave.erl, line 197)
**exit:not_alive

Am I doing something wrong here?

As a sidenote, I also looked at gproc's distributed test here, but it's manually starting a number of slave nodes rather than using the built-in Eunit functionality.

Can someone give me some examples of how to use use the node test fixture?

Thanks,

Upvotes: 0

Views: 288

Answers (4)

Viacheslav Kovalev
Viacheslav Kovalev

Reputation: 1745

My suggestion is that you run your master node with disabled distribution. Enable it with -sname key (I assume, your example code is located in module node_test):

> erl -sname master
(master@hostname)1> c(node_test).
> node_test:test().

But it is not all. To run this code in new versions of erlang, you should make a little changes:

cluster_test_() ->  
    {node, foo,
     fun ({Node, StopNet}) ->
        ?debugFmt("Node ~p", [Node]),
        ?debugFmt("StopNet ~p", [StopNet]),
        [?_assertEqual(pong, net_adm:ping(Node))]
     end
    }.

Note, function argument now contains not node name, but tuple with two elements. First element is remote node name, second - is boolean flag which always false (at least for now). For more detail refer to eunit sources

Upvotes: 0

danechkin
danechkin

Reputation: 1306

If you are going with multi-node tests and eunit keep in mind then eunit ifdefs in modules will change it's checksums, and if you say have one module compiled with ifdef eunit and another is not you will have errors if try to call remote functions.

Upvotes: 0

RichardC
RichardC

Reputation: 10557

Hm, I never got the slave node functionality to work properly, so it shouldn't be a documented feature. I guess it ended up in the docs while I still thought it was working. I'll probably have to fix the docs.

Upvotes: 0

mpm
mpm

Reputation: 3584

Common Test was written especially for testing bigger systems.

Other that official documentation you can find very good introduction to theme here. And chapter evens ends with small snippet howto integrate existing eunit tests into Common Test.

Upvotes: 0

Related Questions