[erlang-questions] testing asynchronous code

Martin DeMello <>
Tue Apr 20 08:27:22 CEST 2010


On Mon, Apr 19, 2010 at 8:21 PM, David Mercer <> wrote:
>
> I assume your issue is that you cannot test system state right after a cast
> because its processing is asynchronous?

Yes, exactly.

> Alternatively, you might could[1] add a "sync" call into the server, which
> does nothing, but you know when it returns that all prior casts have been
> processed, and then you can make your asserts on the server or system state,
> etc.  (If the casts are passing processing off to other processes, the sync
> call would have to "sync" with them before returning.)

This was one of the things I thought about, but have no idea how to
actually do. Where and how would I keep track of which casts are
processed? Here's a concrete example - I have a tree of objects in
mnesia, which I want to run some cleanup code on. So I send a cast to
the root, which cleans up its associated resource, sends casts to all
its children, and then deletes itself from the db, and so on
recursively. How would I go about syncing on that? For example, I
could wait for all the objects to be deleted from the db, but that's
syncing on the "side effects" of the cast, rather than explicitly when
the function it calls has returned.

martin


More information about the erlang-questions mailing list