forked from oban-bg/oban
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unbox or escape sandbox for integration tests
- Loading branch information
Showing
9 changed files
with
124 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
defmodule Oban.Integration.DatabaseTriggerTest do | ||
use Oban.Case | ||
|
||
alias Ecto.Adapters.SQL.Sandbox | ||
|
||
test "dispatching jobs from a queue via database trigger" do | ||
start_supervised_oban!(notifier: Oban.Notifiers.Postgres, queues: [alpha: 5]) | ||
Sandbox.unboxed_run(Repo, fn -> | ||
start_supervised_oban!(notifier: Oban.Notifiers.Postgres, queues: [alpha: 5]) | ||
|
||
insert!(ref: 1, action: "OK") | ||
|
||
insert!(ref: 1, action: "OK") | ||
assert_receive {:ok, 1} | ||
|
||
assert_receive {:ok, 1} | ||
delete_oban_data!() | ||
end) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,29 @@ | ||
defmodule Oban.Integration.DynamicRepoTest do | ||
use Oban.Case | ||
|
||
import Ecto.Query | ||
|
||
alias Oban.Test.DynamicRepo | ||
|
||
setup do | ||
test "executing jobs using a dynamic repo" do | ||
{:ok, repo_pid} = start_supervised({DynamicRepo, name: nil}) | ||
|
||
DynamicRepo.put_dynamic_repo(repo_pid) | ||
DynamicRepo.put_dynamic_repo(nil) | ||
|
||
on_exit(fn -> | ||
DynamicRepo.put_dynamic_repo(repo_pid) | ||
end) | ||
|
||
{:ok, repo_pid: repo_pid} | ||
end | ||
|
||
test "job execution", context do | ||
name = start_oban!(context.repo_pid, queues: [alpha: 1]) | ||
job_ref = insert_job!(name).ref | ||
|
||
assert_receive {:ok, ^job_ref} | ||
end | ||
on_exit(fn -> DynamicRepo.put_dynamic_repo(repo_pid) end) | ||
|
||
test "rollback job insertion after transaction failure", context do | ||
name = start_oban!(context.repo_pid, queues: [alpha: 1]) | ||
name = make_ref() | ||
|
||
{:ok, _app_repo_pid} = | ||
start_supervised(%{DynamicRepo.child_spec(name: :app_repo) | id: :app_repo}) | ||
opts = [ | ||
get_dynamic_repo: fn -> repo_pid end, | ||
name: name, | ||
peer: Oban.Case.Peer, | ||
queues: [alpha: 1], | ||
repo: DynamicRepo, | ||
] | ||
|
||
DynamicRepo.put_dynamic_repo(:app_repo) | ||
start_supervised!({Oban, opts}) | ||
|
||
ref = System.unique_integer([:positive, :monotonic]) | ||
|
||
assert {:error, :failure, :wat, %{job: %Oban.Job{args: %{ref: ^ref, action: "OK"}}}} = | ||
name | ||
|> Oban.insert(Ecto.Multi.new(), :job, Worker.new(%{ref: ref, action: "OK"})) | ||
|> Ecto.Multi.run(:failure, fn _repo, _ -> {:error, :wat} end) | ||
|> DynamicRepo.transaction() | ||
|
||
refute_receive {:ok, ^ref} | ||
end | ||
|
||
defp start_oban!(repo_pid, opts) do | ||
opts | ||
|> Keyword.merge(repo: DynamicRepo, get_dynamic_repo: fn -> repo_pid end) | ||
|> start_supervised_oban!() | ||
end | ||
Oban.insert!(name, Worker.new(%{ref: 1, action: "OK"})) | ||
|
||
defp insert_job!(oban_name) do | ||
ref = System.unique_integer([:positive, :monotonic]) | ||
{:ok, job} = Oban.insert(oban_name, Worker.new(%{ref: ref, action: "OK"})) | ||
%{ref: ref, job: job} | ||
assert_receive {:ok, 1} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.