From 2c9af46df88783f6260a7df8b4f56833c38dde2f Mon Sep 17 00:00:00 2001 From: Giovanni Liva Date: Wed, 9 Aug 2023 13:44:14 +0200 Subject: [PATCH] emit in goroutine Signed-off-by: Giovanni Liva --- lifecycle-operator/controllers/common/eventsender.go | 2 +- lifecycle-operator/controllers/common/eventsender_test.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lifecycle-operator/controllers/common/eventsender.go b/lifecycle-operator/controllers/common/eventsender.go index 7550e15676..969a0ff334 100644 --- a/lifecycle-operator/controllers/common/eventsender.go +++ b/lifecycle-operator/controllers/common/eventsender.go @@ -43,7 +43,7 @@ func (e *EventMultiplexer) register(emitter IEvent) { func (e *EventMultiplexer) Emit(phase apicommon.KeptnPhaseType, eventType string, reconcileObject client.Object, status string, message string, version string) { for _, emitter := range e.emitters { e.logger.Info(fmt.Sprintf("Emitting event using %T", emitter)) - emitter.Emit(phase, eventType, reconcileObject, status, message, version) + go emitter.Emit(phase, eventType, reconcileObject, status, message, version) } } diff --git a/lifecycle-operator/controllers/common/eventsender_test.go b/lifecycle-operator/controllers/common/eventsender_test.go index 714ebe76a1..a8a004bf3b 100644 --- a/lifecycle-operator/controllers/common/eventsender_test.go +++ b/lifecycle-operator/controllers/common/eventsender_test.go @@ -184,7 +184,9 @@ func TestEventSender_Multiplexer_emit(t *testing.T) { // fire a new event msg := "my special message" emitter.Emit(common.PhaseAppDeployment, "", nil, "", msg, "") - // assert we got one event each + // assert we got one event + // let's wait few seconds so the async emit takes place + <-time.After(3 * time.Second) require.Equal(t, 2, len(emitter.emitters)) require.Equal(t, 1, len(em1.events)) require.Equal(t, 1, len(em2.events))