-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor OpentelemetryOban test setup
- Loading branch information
1 parent
b6c577b
commit e43906e
Showing
11 changed files
with
80 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# This file is responsible for configuring your application | ||
# and its dependencies with the aid of the Mix.Config module. | ||
import Config | ||
|
||
try do | ||
import_config "#{Mix.env()}.exs" | ||
rescue | ||
_ -> :ok | ||
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Config | ||
|
||
config :opentelemetry_oban, | ||
ecto_repos: [TestRepo] | ||
|
||
config :opentelemetry_oban, TestRepo, | ||
hostname: "localhost", | ||
username: "postgres", | ||
password: "postgres", | ||
database: "opentelemetry_oban_test", | ||
pool: Ecto.Adapters.SQL.Sandbox |
This file was deleted.
Oops, something went wrong.
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
5 changes: 5 additions & 0 deletions
5
instrumentation/opentelemetry_oban/priv/test_repo/migrations/1_setup_tables.exs
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
defmodule OpentelemetryOban.TestRepo.Migrations.SetupTables do | ||
use Ecto.Migration | ||
|
||
def up, do: Oban.Migrations.up() | ||
end |
8 changes: 8 additions & 0 deletions
8
instrumentation/opentelemetry_oban/test/support/jobs/test_job.ex
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
defmodule TestJob do | ||
use Oban.Worker, queue: :events, max_attempts: 1 | ||
|
||
@impl Oban.Worker | ||
def perform(_job) do | ||
:ok | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
instrumentation/opentelemetry_oban/test/support/jobs/test_job_that_returns_error.ex
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
defmodule TestJobThatReturnsError do | ||
use Oban.Worker, queue: :events, max_attempts: 1 | ||
|
||
@impl Oban.Worker | ||
def perform(_job) do | ||
{:error, :something} | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
instrumentation/opentelemetry_oban/test/support/jobs/test_job_that_throws_exception.ex
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
defmodule TestJobThatThrowsException do | ||
use Oban.Worker, queue: :events, max_attempts: 1 | ||
|
||
@impl Oban.Worker | ||
def perform(_job) do | ||
raise %UndefinedFunctionError{ | ||
message: "function Some.error/0 is undefined (module Some is not available)" | ||
} | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
instrumentation/opentelemetry_oban/test/support/jobs/test_job_with_inner_span.ex
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
defmodule TestJobWithInnerSpan do | ||
use Oban.Worker, queue: :events, max_attempts: 1 | ||
require OpenTelemetry.Tracer | ||
|
||
@impl Oban.Worker | ||
def perform(_job) do | ||
OpenTelemetry.Tracer.with_span "span inside the job" do | ||
:ok | ||
end | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
instrumentation/opentelemetry_oban/test/support/test_helpers.ex
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
defmodule TestHelpers do | ||
def remove_oban_handlers() do | ||
Enum.each(:telemetry.list_handlers([:oban]), fn handler -> | ||
:telemetry.detach(handler[:id]) | ||
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,75 +1,12 @@ | ||
ExUnit.start(capture_log: true) | ||
TestRepo.start_link() | ||
|
||
TestRepo.start_link( | ||
database: "opentelemetry_oban_test", | ||
hostname: "localhost", | ||
username: "postgres", | ||
password: "postgres", | ||
pool: Ecto.Adapters.SQL.Sandbox | ||
) | ||
ExUnit.start(capture_log: true) | ||
|
||
Ecto.Adapters.SQL.Sandbox.mode(TestRepo, {:shared, self()}) | ||
|
||
defmodule PrepareOban do | ||
use Ecto.Migration | ||
def up, do: Oban.Migrations.up() | ||
end | ||
|
||
Ecto.Migrator.run(TestRepo, [{0, PrepareOban}], :up, all: true) | ||
TestRepo.query("TRUNCATE oban_jobs", []) | ||
|
||
Oban.start_link( | ||
repo: TestRepo, | ||
plugins: [Oban.Plugins.Pruner], | ||
notifier: Oban.Notifiers.PG, | ||
testing: :manual | ||
) | ||
|
||
defmodule TestJob do | ||
use Oban.Worker, queue: :events, max_attempts: 1 | ||
|
||
@impl Oban.Worker | ||
def perform(_job) do | ||
:ok | ||
end | ||
end | ||
|
||
defmodule TestJobWithInnerSpan do | ||
use Oban.Worker, queue: :events, max_attempts: 1 | ||
require OpenTelemetry.Tracer | ||
|
||
@impl Oban.Worker | ||
def perform(_job) do | ||
OpenTelemetry.Tracer.with_span "span inside the job" do | ||
:ok | ||
end | ||
end | ||
end | ||
|
||
defmodule TestJobThatReturnsError do | ||
use Oban.Worker, queue: :events, max_attempts: 1 | ||
|
||
@impl Oban.Worker | ||
def perform(_job) do | ||
{:error, :something} | ||
end | ||
end | ||
|
||
defmodule TestJobThatThrowsException do | ||
use Oban.Worker, queue: :events, max_attempts: 1 | ||
|
||
@impl Oban.Worker | ||
def perform(_job) do | ||
raise %UndefinedFunctionError{ | ||
message: "function Some.error/0 is undefined (module Some is not available)" | ||
} | ||
end | ||
end | ||
|
||
defmodule TestHelpers do | ||
def remove_oban_handlers() do | ||
Enum.each(:telemetry.list_handlers([:oban]), fn handler -> | ||
:telemetry.detach(handler[:id]) | ||
end) | ||
end | ||
end |