Testing DedupeChannel
Explore testing strategies for the DedupeChannel in Phoenix, using helper functions to manage channel state and message broadcasting. Understand how to verify message order, buffer draining, and socket state changes effectively. This lesson equips you to write robust and clear tests for real-time Elixir applications.
We'll cover the following...
DedupeChannel
Our DedupeChannel module contains more complex logic than WildcardChannel. We will leverage both Channel and Elixir testing patterns to develop complete tests for our Channel’s logic. Our tests will use message broadcasting to and from the DedupeChannel. This is the last technique we’ll cover for writing Channel tests.
Our join/3 function is straightforward in DedupeChannel, so we won’t add tests for it. We’ll start with tests to check that our Channel state changes when we broadcast a new number to our Channel. Let’s write a few helper functions that make our tests much easier to write and read.
We use broadcast_from!/3 to trigger handle_out of our Channel. The broadcast function invokes the PubSub callbacks in the ...