Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joaothallis authored and rai200890 committed Dec 17, 2020
1 parent a9d268b commit fc6d003
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/new_relic/reporter.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
defmodule EctoJobScheduler.NewRelic.Reporter do
@moduledoc false

@callback start() :: term()
@callback start_transaction(:other) :: term()

@callback add_attributes(keyword()) :: term()
@callback stop_transaction(:other) :: term()

@callback fail(pid(), map()) :: term()
@callback add_attributes(keyword()) :: term()

@callback complete(pid(), atom()) :: term()
@callback fail(map()) :: term()
end
17 changes: 15 additions & 2 deletions test/job_queue_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule EctoJobScheduler.JobQueueTest do
setup do
if unquote(job_queue) == TestJobQueueNewRelic do
ReporterMock
|> Mox.expect(:start, fn -> :ok end)
|> Mox.expect(:start_transaction, fn _ -> :ok end)
|> Mox.expect(:add_attributes, fn _ -> :ok end)
end

Expand All @@ -35,6 +35,9 @@ defmodule EctoJobScheduler.JobQueueTest do

job = Repo.one(unquote(job_queue))

Mox.expect(ReporterMock, :stop_transaction, fn _ -> :ok end)
Mox.expect(ReporterMock, :fail, fn _ -> :ok end)

assert {:ok, %{test_job: :xablau}} =
EctoJobHelpers.dispatch_job(Repo, unquote(job_queue), job)

Expand All @@ -58,6 +61,10 @@ defmodule EctoJobScheduler.JobQueueTest do

job = Repo.one(unquote(job_queue))

Mox.expect(ReporterMock, :fail, fn _ -> :ok end)

Mox.expect(ReporterMock, :stop_transaction, fn _ -> :ok end)

assert {:error, :test_job, :xablau, %{}} =
EctoJobHelpers.dispatch_job(Repo, unquote(job_queue), job)

Expand Down Expand Up @@ -86,6 +93,9 @@ defmodule EctoJobScheduler.JobQueueTest do

job = Repo.one(unquote(job_queue))

Mox.expect(ReporterMock, :stop_transaction, fn _ -> :ok end)
Mox.expect(ReporterMock, :fail, fn _ -> :ok end)

assert {:ok, :xablau} == EctoJobHelpers.dispatch_job(Repo, unquote(job_queue), job)

assert Repo.all(unquote(job_queue)) == []
Expand All @@ -100,9 +110,12 @@ defmodule EctoJobScheduler.JobQueueTest do

test "#{job_queue} when job doesn't return multi and fails, should update job attempt" do
if unquote(job_queue) == TestJobQueueNewRelic do
Mox.expect(ReporterMock, :fail, fn _, _ -> :ok end)
Mox.expect(ReporterMock, :fail, fn _ -> :ok end)
end

Mox.expect(ReporterMock, :stop_transaction, fn _ -> :ok end)
Mox.expect(ReporterMock, :fail, fn _ -> :ok end)

job_args = %{
"type" => "TestJobNotMultiError",
"context" => %{some: :thing}
Expand Down

0 comments on commit fc6d003

Please sign in to comment.