diff --git a/lib/new_relic/reporter.ex b/lib/new_relic/reporter.ex index 3b74d21..cff4ee8 100644 --- a/lib/new_relic/reporter.ex +++ b/lib/new_relic/reporter.ex @@ -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 diff --git a/test/job_queue_test.exs b/test/job_queue_test.exs index caf581e..9658644 100644 --- a/test/job_queue_test.exs +++ b/test/job_queue_test.exs @@ -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 @@ -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) @@ -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) @@ -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)) == [] @@ -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}