Fleet.Testing (fleet v0.1.0)

Copy Markdown View Source

Testing helpers for Fleet background jobs.

Provides utilities to run worker jobs synchronously and assert on enqueued jobs without starting a full Broadway pipeline.

Example

defmodule MyApp.MyWorkerTest do
  use ExUnit.Case, async: true
  use Fleet.Testing, repo: MyApp.Repo

  test "runs the worker" do
    assert :ok = perform_job(MyApp.Workers.SendEmail, %{"to" => "alice@example.com"})

    assert_enqueued(
      worker: MyApp.Workers.FollowUp,
      args: %{"to" => "alice@example.com"}
    )
  end
end

Summary

Functions

Returns all enqueued jobs matching the given filter criteria (:worker, :args, :queue). Queries both the database (Ecto Sandbox aware) and in-memory test tracker.

Asserts that a job matching the given criteria was enqueued.

Clears all recorded enqueued jobs.

Ensures the testing ETS tracker table exists.

Runs a worker synchronously with the provided arguments or Fleet.Job struct. Returns the worker's perform result (:ok, {:ok, val}, {:error, reason}, {:snooze, seconds}, {:cancel, reason}).

Asserts that no job matching the given criteria was enqueued.

Functions

all_enqueued(filters \\ [])

Returns all enqueued jobs matching the given filter criteria (:worker, :args, :queue). Queries both the database (Ecto Sandbox aware) and in-memory test tracker.

assert_enqueued(filters)

Asserts that a job matching the given criteria was enqueued.

clear_enqueued(repo \\ nil)

Clears all recorded enqueued jobs.

ensure_tracker_started()

Ensures the testing ETS tracker table exists.

perform_job(worker, args, job_opts \\ [])

Runs a worker synchronously with the provided arguments or Fleet.Job struct. Returns the worker's perform result (:ok, {:ok, val}, {:error, reason}, {:snooze, seconds}, {:cancel, reason}).

refute_enqueued(filters)

Asserts that no job matching the given criteria was enqueued.