Skip to content

Commit

Permalink
Fix discovery dispatch accumulating errors (#3272)
Browse files Browse the repository at this point in the history
  • Loading branch information
arbulu89 authored Feb 3, 2025
1 parent d3911e3 commit f6f638f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/trento/discovery.ex
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ defmodule Trento.Discovery do
{:ok, :ok} ->
:ok

{:ok, {:error, errors}} ->
{:error, errors}

{{:error, error}, :ok} ->
{:error, [error]}

Expand Down
29 changes: 29 additions & 0 deletions test/trento/discovery_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ defmodule Trento.DiscoveryTest do

import Trento.Factory

import Trento.DiscoveryFixturesHelper

alias Trento.Discovery

alias Trento.Discovery.{
Expand Down Expand Up @@ -144,4 +146,31 @@ defmodule Trento.DiscoveryTest do
assert %DiscardedDiscoveryEvent{payload: ^event} =
discarded_event
end

test "should continue accumulating discovery events if the first command fails" do
error = :any_error

sap_discovery_payload_entry =
"sap_system_discovery_application"
|> load_discovery_event_fixture()
|> Map.get("payload")
|> Enum.at(0)

event = %{
"agent_id" => Faker.UUID.v4(),
"discovery_type" => "sap_system_discovery",
"payload" => [sap_discovery_payload_entry, sap_discovery_payload_entry]
}

Trento.Commanded.Mock
|> expect(:dispatch, 1, fn _ -> {:error, error} end)
|> expect(:dispatch, 1, fn _ -> :ok end)

{:error, [^error]} = Discovery.handle(event)

[discarded_event] = Trento.Repo.all(DiscardedDiscoveryEvent)

assert %DiscardedDiscoveryEvent{payload: ^event} =
discarded_event
end
end

0 comments on commit f6f638f

Please sign in to comment.