Testing Periodic Actions

At last we can get back to our beloved Soggy Waffle application. We saw how to test a GenServer whose job is essentially to hold some state. Another common use for GenServers is to have a process in your system that performs an action periodically. For example, you could have a GenServer that resets a cache every five minutes or a GenServer that looks for changes to system environment variables every few seconds and updates other parts of your system when that happens.

For Soggy Waffle, we need something like what we just described. Soggy Waffle’s purpose is to alert us in case there’s going to be rain in the next few hours. To do that, the application needs to periodically call out to the weather API to check if there’s ...

Get Testing Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.