From 6cd5198fc51e439d0a5791b17005fa6b4b10ecc0 Mon Sep 17 00:00:00 2001 From: KEDA Automation <94457271+keda-automation@users.noreply.github.com> Date: Thu, 3 Oct 2024 01:29:14 +0200 Subject: [PATCH] fix: EventGrid event emiter e2e test doesn't fail randomly (#6196) Signed-off-by: Jorge Turrado Co-authored-by: Jorge Turrado --- .../azureeventgridtopic_test.go | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/internals/eventemitter/azureeventgridtopic/azureeventgridtopic_test.go b/tests/internals/eventemitter/azureeventgridtopic/azureeventgridtopic_test.go index 55aaa463c5a..ae00ea8173d 100644 --- a/tests/internals/eventemitter/azureeventgridtopic/azureeventgridtopic_test.go +++ b/tests/internals/eventemitter/azureeventgridtopic/azureeventgridtopic_test.go @@ -42,6 +42,7 @@ var ( clusterName = "test-cluster" expectedSubject = fmt.Sprintf("/%s/%s/scaledobject/%s", clusterName, namespace, scaledObjectName) expectedSource = fmt.Sprintf("/%s/keda/keda", clusterName) + expectedType = "keda.scaledobject.ready.v1" monitoredDeploymentName = "monitored-deployment" sutDeploymentName = "sut-deployment" scaledObjectName = fmt.Sprintf("%s-so", testName) @@ -270,13 +271,17 @@ func checkMessage(t *testing.T, count int, client *azservicebus.Client) { assert.NoErrorf(t, err, "cannot receive messages - %s", err) assert.NotEmpty(t, messages) - var message = string(messages[0].Body) - - event := messaging.CloudEvent{} - err = json.Unmarshal([]byte(message), &event) - assert.NoErrorf(t, err, "cannot retrieve message - %s", err) + found := false + for _, message := range messages { + event := messaging.CloudEvent{} + err = json.Unmarshal(message.Body, &event) + assert.NoErrorf(t, err, "cannot retrieve message - %s", err) + if expectedSubject == *event.Subject && + expectedSource == event.Source && + expectedType == event.Type { + found = true + } + } - assert.Equal(t, expectedSubject, *event.Subject) - assert.Equal(t, expectedSource, event.Source) - assert.Equal(t, "keda.scaledobject.ready.v1", event.Type) + assert.True(t, found) }