Skip to content

Commit

Permalink
fix: EventGrid event emiter e2e test doesn't fail randomly (kedacore#…
Browse files Browse the repository at this point in the history
…6196)

Signed-off-by: Jorge Turrado <[email protected]>
Co-authored-by: Jorge Turrado <[email protected]>
  • Loading branch information
keda-automation and JorTurFer authored Oct 2, 2024
1 parent caba419 commit 6cd5198
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

0 comments on commit 6cd5198

Please sign in to comment.