Skip to content

Commit

Permalink
document the test api
Browse files Browse the repository at this point in the history
  • Loading branch information
ananthakumaran committed Nov 18, 2019
1 parent ffd6219 commit 6529199
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/exq/mock.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ defmodule Exq.Mock do
@timeout 30000

defmodule State do
@moduledoc false
defstruct default_mode: :redis, jobs: %{}, modes: %{}
end

### Public api

@doc """
Start Mock server
* `mode` - The default mode that's used for all tests. See `set_mode/1` for details.
"""
def start_link(options \\ []) do
queue_adapter = Config.get(:queue_adapter)

Expand All @@ -25,10 +31,22 @@ defmodule Exq.Mock do
GenServer.start_link(__MODULE__, options, name: __MODULE__)
end

@doc """
Set the mode for current test
* `:redis` - jobs get enqueued and processed via redis.
* `:fake` - jobs get enqueued in a local queue
* `:inline` - jobs get executed in the same process
"""
def set_mode(mode) when mode in [:redis, :inline, :fake] do
GenServer.call(__MODULE__, {:mode, self(), mode}, @timeout)
end

@doc """
List of enqueued jobs
This only works if the mode is set to `:fake`
"""
def jobs do
GenServer.call(__MODULE__, {:jobs, self()}, @timeout)
end
Expand All @@ -40,6 +58,7 @@ defmodule Exq.Mock do
{:ok, %State{default_mode: Keyword.get(options, :mode, :redis)}}
end

@doc false
def enqueue(pid, queue, worker, args, options) do
{:ok, runnable} =
GenServer.call(
Expand All @@ -51,6 +70,7 @@ defmodule Exq.Mock do
runnable.()
end

@doc false
def enqueue_at(pid, queue, time, worker, args, options) do
{:ok, runnable} =
GenServer.call(
Expand All @@ -62,6 +82,7 @@ defmodule Exq.Mock do
runnable.()
end

@doc false
def enqueue_in(pid, queue, offset, worker, args, options) do
{:ok, runnable} =
GenServer.call(
Expand Down

0 comments on commit 6529199

Please sign in to comment.