[erlang-questions] How to mimic Erlang nodes in PropEr statem test

Nyirő Gergő <>
Fri Jan 25 21:18:01 CET 2019


On Fri, Jan 25, 2019 at 2:03 PM Fred Hebert <> wrote:
>
> On 01/23, Nyirő Gergő wrote:
> >
> >Right now I have only one gen_server (crdt_server) per node, but I would
> >like to add an event handler (crdt_event) which could persist the content
> >of the crdt set or log the executed commands.
> >
>
> Okay, so that's essentially duplicating the messages: send them to the
> server, but you want to asynchronously log with another process. Do I
> understand this right?

Yes, and I can also write the members of the CRDT set (which will be a
map in the final version) to disk with an extra event handler which
would be registered only in the production code.

> >Other solution would be to pass the NameOrPid of the crdt_event processes to
> >crdt_server processes, but a process registry could be a more elegant solution.
> >
>
> This is a possibility. There are other options such as:
>
> - Each crdt_server is spawned under a crdt_sup. The crdt_sup works by
>   booting two processes: crdt_log (first) and crdt_server (second). Each
>   is passed a name that identifies the server ("crdt_1", `node_a`, or
>   whatever)
> - By using a dynamic process registry like gproc (see
>   https://hex.pm/packages/gproc) and replacing the name registration
>   from {local, Name} to {via, gproc, {n, l, {crdt_log, Name}}} and {via,
>   gproc, {n, l, {crdt_server, Name}}} you can give them unique names
>   that they can "know"
> - On every call the crdt_server wants to log, it can call a function
>   from the crdt_log module, such as crdt_log:do_log(Name, Contents)

I think the dynamic process registry was that I was looking for.
(Good example, easy to understand).

> >Should I use ct_property_test [1] instead?
> >
>
> This is an experimental call or module to integrate the results of your
> properties to the common test flow. You're free to use it if you want to
> integrate everything into CT.

I misunderstood  the intention of the ct_property_test. I thought the test suite
parameterization and dynamic node creation of ct can be passed to PropEr tests.
But the warning is scary enough to avoid this solution:)

> I personally maintain the rebar3 plugin for PropEr and I tend to prefer
> it for some of the additional features it adds:

Nice plugin (I found it through hex), makes my work easier.

Thanks for the advice. Regards,
Gergő


More information about the erlang-questions mailing list