test: fix flaky tests

chore: address credo issues
This commit is contained in:
Zach Daniel 2024-02-20 13:14:02 -05:00
parent 12f4207193
commit 398d90600f
6 changed files with 29 additions and 8 deletions

View file

@ -10,6 +10,7 @@ if Mix.env() == :test do
config :ash_oban, ecto_repos: [AshOban.Test.Repo]
config :ash_oban, :oban,
testing: :manual,
repo: AshOban.Test.Repo,
prefix: "private",
plugins: [

View file

@ -1,4 +1,7 @@
defmodule AshOban.ActorPersister do
@moduledoc """
A behaviour for storing and retrieving an actor from oban job arguments
"""
@type actor_json :: any
@type actor :: any

View file

@ -716,7 +716,7 @@ defmodule AshOban do
|> Enum.uniq()
# we drain each queue twice to do schedulers and then workers
drain_queues(queues ++ queues, opts)
drain_queues(queues, opts)
end
def do_schedule_and_run_triggers(resource_or_api_or_otp_app, opts) do
@ -752,7 +752,7 @@ defmodule AshOban do
|> Enum.uniq()
# we drain each queue twice to do schedulers and then workers
drain_queues(queues ++ queues, opts)
drain_queues(queues, opts)
true ->
resource_or_api_or_otp_app
@ -768,10 +768,16 @@ defmodule AshOban do
defp drain_queues(queues, opts) do
if opts[:drain_queues?] do
Enum.reduce(queues, default_acc(), fn queue, acc ->
Enum.reduce(queues ++ queues, default_acc(), fn queue, acc ->
[queue: queue]
|> Keyword.merge(
Keyword.take(opts, [:queue, :with_limit, :with_recursion, :with_safety, :with_scheduled])
Keyword.take(opts, [
:queue,
:with_limit,
:with_recursion,
:with_safety,
:with_scheduled
])
)
|> Oban.drain_queue()
|> Map.put(:queues_not_drained, [])
@ -783,7 +789,7 @@ defmodule AshOban do
end
end
defp default_acc() do
defp default_acc do
%{
discard: 0,
cancelled: 0,

View file

@ -107,8 +107,9 @@ defmodule AshOban.MixProject do
if System.get_env("ASH_OBAN_CI_OBAN_PRO") == "false" do
[]
else
# See the getting started guide why this is only dev/test
[{:oban_pro, "~> 1.0", repo: "oban", only: [:dev]}]
# We can't currently use this as we don't have a license for oban_pro that we can use
# [{:oban_pro, "~> 1.0", repo: "oban", only: [:dev,]}]
[]
end
oban_dep ++
@ -142,7 +143,8 @@ defmodule AshOban.MixProject do
"spark.cheat_sheets_in_search": "spark.cheat_sheets_in_search --extensions AshOban",
"test.gen.migration": "ecto.gen.migration --migrations-path=test_migrations",
"test.migrate": "ecto.migrate --migrations-path=test_migrations",
"test.create": "ecto.create"
"test.create": "ecto.create",
"test.setup": ["test.create", "test/migrate"]
]
end
end

View file

@ -12,6 +12,13 @@ defmodule AshObanTest do
:ok
end
setup do
Enum.each(
[:triggered_process, :triggered_process_2, :triggered_say_hello],
&Oban.drain_queue(queue: &1)
)
end
test "nothing happens if no records exist" do
assert %{success: 1} = AshOban.Test.schedule_and_run_triggers(Triggered)
end

View file

@ -1,7 +1,9 @@
defmodule AshOban.Test.ActorPersister do
@moduledoc false
use AshOban.ActorPersister
defmodule FakeActor do
@moduledoc false
defstruct id: nil
end