Bumps vendored Oban Pro from 1.6.13 to 1.7.0, which transitively bumps oban core to 2.22.1 (requires migrations v14) and db_connection to 2.10.0. - mix.exs constraint: ~> 1.6 → ~> 1.7 - vendor/oban_pro/ replaced with v1.7.0 hex package - migration 20260430142200: Oban core v12 → v14 (must run first) - migration 20260430142241: Oban Pro 1.7.0 schema additions Also corrects a pre-existing constraint name in AgentAssignment that was left stale by the equipment→devices rename migration (20260117190134). The unique index is named agent_assignments_device_id_index, but the schema's unique_constraint/3 still pointed at the old equipment_id name, causing the test suite to surface Ecto.ConstraintError instead of a changeset error. Required to get the suite green for this upgrade.
48 lines
1.2 KiB
Markdown
48 lines
1.2 KiB
Markdown
# Testing
|
|
|
|
Use `Oban.Pro.Testing` — a drop-in replacement for `Oban.Testing` with Pro helpers.
|
|
|
|
## Configuration
|
|
|
|
```elixir
|
|
# config/test.exs
|
|
config :my_app, Oban, testing: :manual
|
|
```
|
|
|
|
## Helpers
|
|
|
|
**Unit testing** — execute jobs without the database:
|
|
|
|
- `perform_job/3` — execute a single job
|
|
- `perform_callback/4` — execute batch callbacks
|
|
- `perform_chunk/3` — execute chunk workers
|
|
|
|
**Integration testing** — insert and execute jobs:
|
|
|
|
- `drain_jobs/1` — execute jobs across queues
|
|
- `run_workflow/2` — insert and execute a workflow
|
|
- `run_batch/2` — insert and execute a batch
|
|
- `run_chunk/2` — insert and execute chunked jobs
|
|
|
|
**Always use `drain_jobs/1` instead of `Oban.drain_queue/2`:**
|
|
|
|
- Drains all queues with `queue: :all`
|
|
- Handles workflows, batches, and chains correctly
|
|
- Supports recursive draining
|
|
- Returns completion counts
|
|
|
|
```elixir
|
|
defmodule MyApp.WorkerTest do
|
|
use MyApp.DataCase, async: false
|
|
use Oban.Pro.Testing, repo: MyApp.Repo
|
|
|
|
test "processes job" do
|
|
assert :ok == perform_job(SomeWorker, %{user_id: 123})
|
|
end
|
|
|
|
test "drains enqueued jobs" do
|
|
MyApp.enqueue_work()
|
|
assert %{completed: 3} = drain_jobs(queue: :all)
|
|
end
|
|
end
|
|
```
|