How to assert some process received some message?

Three ways I know you can do this but neither are very straight forward:

  • Use the tracing BIFs to trace messages sent to that process. You can then match on them to get the ones in which you are interested. AFAIK there is no elixir library which supports this so you need to use an erlang interface, for example :dbg.
  • Trace calls to the handle_info/2 function in your module in the process in which you are interested.
  • Use the erlang :sys module to install a special debug handler then turn on tracing with :sys.trace/2. More high level and OTPish, but I have never tested it.

The tracing always works but might be a bit tricky to set up. It also works very well if you want inspect running production systems. Not surprising as that is what the tracing was designed for. :grinning:

5 Likes