gen_queue v0.1.8 GenQueue.Test View Source
Conveniences for testing queues.
This module allows us to create or use existing adapter “mock” libraries. A mock adapter is an adapter that mirrors the functionality of an exisiting adapter, but instead sends the item to the mailbox of a specified process.
defmodule Adapter do
use GenQueue.Adapter
def handle_push(gen_queue, item, _opts) do
GenQueue.Test.send_item(gen_queue, item)
end
end
We can then test that our items are being pushed correctly.
use ExUnit.Case, async: true
import GenQueue.Test
# This test assumes we have a GenQueue named Queue
setup do
setup_test_queue(Queue)
end
test "that our queue works" do
Queue.start_link()
Queue.push(:foo)
assert_recieve(:foo)
end
Most adapters will provide a mirrored “mock” adapter to use with your tests.
Link to this section Summary
Functions
Removes any current queue receiver for a GenQueue
Sends an item to the mailbox of a process set for a GenQueue
Sets the queue reciever as the current process for a GenQueue
Sets the queue reciever as the current process for a GenQueue
Link to this section Functions
Removes any current queue receiver for a GenQueue.
send_item(GenQueue.t(), any()) :: any()
Sends an item to the mailbox of a process set for a GenQueue.
setup_global_test_queue(GenQueue.t(), atom()) :: :ok
Sets the queue reciever as the current process for a GenQueue.
The current process is also given a name. This ensures queues that run outside of the current process are able to send items to the correct mailbox.
Sets the queue reciever as the current process for a GenQueue.