Skip to content

Commit

Permalink
Ensure queues are running during start_supervised
Browse files Browse the repository at this point in the history
A common cause of flickering tests are race conditions between when a
queue's producer returns from `init` and when it finishes
`handle_continue`. Producers can only accept notifications after
`handle_continue`, and they won't receive messages sent beforehand.
  • Loading branch information
sorentwo committed Jan 19, 2024
1 parent 5f5c738 commit e0c4051
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion test/support/case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ defmodule Oban.Case do
repo = Keyword.fetch!(opts, :repo)

attach_auto_allow(repo, name)

start_supervised!({Oban, opts})
ensure_started(name, opts)

name
end
Expand Down Expand Up @@ -134,4 +134,11 @@ defmodule Oban.Case do
end

defp attach_auto_allow(_repo, _name), do: :ok

defp ensure_started(name, opts) do
opts
|> Keyword.get(:queues, [])
|> Keyword.keys()
|> Enum.each(&Oban.check_queue(name, queue: &1))
end
end

0 comments on commit e0c4051

Please sign in to comment.