Elixir 1.4: Tons of unexpected message warnings

So I upgraded to Elixir 1.4.2, ran my tests, and got a ton of warnings:

Because I am (lazy, one man team, part-time elixir programmer, … etc), I write extremely “loose” tests, where I spin up Agents, pass them to the worker being tested, and assert stuff using :erlang.trace. I fully acknowledge that instead, I should write actual mock (noun!) workers, and pass them in, which handle the expected cases as provided by a “contract” … But I really need to keep shipping for now, instead of investing in this.

What would be the best approach for me here? I am not aware of any way to handle_info for Agents… I could create a small GenServer, which captures all handle_info messages silently … I definitely don’t want to turn of the logs during tests, because I’ve caught issues with their help in the past …

I’m probably gonna go with the GenServer approach that captures all messages, but interested in learning perhaps a better way to solve this?

Thanks,

2 Likes

@Mazyod: If I good understand Elixir GenServer have a fallback methods that should be overwritten, so it looks like you are not catching some &handle_info/2 calls.
I suggest you to create your own fallback like:

  # ...
  def handle_info(msg, state) do
    Logger.debug(__MODULE__ <> "receives unexpected message: " <> inspect(msg))
    {:noreply, [], state}
  end
  # ...

and finally set a different Logger level in test environment configuration file.
My recommend values are :info for test environment, :debug for dev environment and :warn for prod environment, so:

  1. simple iex -S mix you will receive all messages
  2. mix test you will receive all messages except debug messages that are useful
  3. when deploying app you will not receive any informations and debug messages - only warnings and errors

Alternatively you could make empty fallback &handle_info/2, but without logging debug message. You can follow TDD and write a test for it that will always fail until you will not add support for this call, so you will have always only one failing test and you will not have any warnings or errors when working with your code outside tests.

1 Like