From ff9076afd4715bee1abde4df206b1b2730247b14 Mon Sep 17 00:00:00 2001 From: Jamie Rodriguez Date: Mon, 10 Jul 2023 16:57:39 +0200 Subject: [PATCH] Only broadcast `HostRemovedFromCluster` when Host is part of Cluster --- lib/trento/application/projectors/host_projector.ex | 11 +++++++++++ .../application/projectors/host_projector_test.exs | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/trento/application/projectors/host_projector.ex b/lib/trento/application/projectors/host_projector.ex index 0104ed5c24..d99f660431 100644 --- a/lib/trento/application/projectors/host_projector.ex +++ b/lib/trento/application/projectors/host_projector.ex @@ -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{}, _, diff --git a/test/trento/application/projectors/host_projector_test.exs b/test/trento/application/projectors/host_projector_test.exs index b5cd403776..d9c57131ff 100644 --- a/test/trento/application/projectors/host_projector_test.exs +++ b/test/trento/application/projectors/host_projector_test.exs @@ -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 @@ -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", %{