Skip to content

Commit

Permalink
Only broadcast HostRemovedFromCluster when Host is part of Cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
jamie-suse committed Jul 10, 2023
1 parent c553018 commit ff9076a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/trento/application/projectors/host_projector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,17 @@ defmodule Trento.HostProjector do
end
end

def after_update(
%HostRemovedFromCluster{host_id: id, cluster_id: cluster_id},
_,
_
) do
TrentoWeb.Endpoint.broadcast("monitoring:hosts", "host_details_updated", %{
id: id,
cluster_id: cluster_id
})
end

def after_update(
%HostDetailsUpdated{},
_,
Expand Down
8 changes: 8 additions & 0 deletions test/trento/application/projectors/host_projector_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ defmodule Trento.HostProjectorTest do
projection = Repo.get!(HostReadModel, host_id)

assert nil == projection.cluster_id

assert_broadcast "host_details_updated",
%{id: ^host_id, cluster_id: ^cluster_id},
1000
end

test "should not set the cluster_id to nil if a HostRemovedFromCluster event is received and the host is not part of the cluster anymore" do
Expand All @@ -172,6 +176,10 @@ defmodule Trento.HostProjectorTest do
projection = Repo.get!(HostReadModel, host_id)

assert cluster_id == projection.cluster_id

refute_broadcast "host_details_updated",
%{id: ^host_id, cluster_id: ^cluster_id},
1000
end

test "should update an existing host when HostDetailsUpdated event is received", %{
Expand Down

0 comments on commit ff9076a

Please sign in to comment.