Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor broker data plane consumer tests conf tests #3934

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 42 additions & 36 deletions test/conformance/helpers/broker_data_plane_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,31 @@ func BrokerV1Beta1ConsumerDataPlaneTestHelper(
secondTriggerName := "second-trigger"
loggerName := "logger-pod"
secondLoggerName := "second-logger-pod"
transformerName := "transformer-pod"
replySource := "origin-for-reply"
eventID := "consumer-broker-tests"
baseSource := "consumer-test-sender"
eventTracker, _ := recordevents.StartEventRecordOrFail(client, loggerName)
secondTracker, _ := recordevents.StartEventRecordOrFail(client, secondLoggerName)

baseEvent := ce.NewEvent()
baseEvent.SetID(eventID)
baseEvent.SetType(testlib.DefaultEventType)
baseEvent.SetSource(baseSource)
baseEvent.SetSpecVersion("1.0")
body := fmt.Sprintf(`{"msg":%q}`, eventID)
if err := baseEvent.SetData(ce.ApplicationJSON, []byte(body)); err != nil {
t.Fatalf("Cannot set the payload of the baseEvent: %s", err.Error())
}

transformMsg := []byte(`{"msg":"Transformed!"}`)
transformPod := resources.EventTransformationPod(
transformerName,
"reply-check-type",
"reply-check-source",
transformMsg,
)
client.CreatePodOrFail(transformPod, testlib.WithService(transformerName))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should've waited here for endpoints ready instead of in the test, but I see you do it in the test, let's see if that helps. Thanks!

client.WaitForAllTestResourcesReadyOrFail()

trigger := client.CreateTriggerOrFailV1Beta1(
Expand All @@ -238,17 +261,19 @@ func BrokerV1Beta1ConsumerDataPlaneTestHelper(
resources.WithSubscriberServiceRefForTriggerV1Beta1(secondLoggerName),
)
client.WaitForResourceReadyOrFail(secondTrigger.Name, testlib.TriggerTypeMeta)
eventID := "consumer-broker-tests"
baseSource := "consumer-test-sender"
baseEvent := ce.NewEvent()
baseEvent.SetID(eventID)
baseEvent.SetType(testlib.DefaultEventType)
baseEvent.SetSource(baseSource)
baseEvent.SetSpecVersion("1.0")
body := fmt.Sprintf(`{"msg":%q}`, eventID)
if err := baseEvent.SetData(ce.ApplicationJSON, []byte(body)); err != nil {
t.Fatalf("Cannot set the payload of the baseEvent: %s", err.Error())
}

transformTrigger := client.CreateTriggerOrFailV1Beta1(
"transform-trigger",
resources.WithBrokerV1Beta1(broker.Name),
resources.WithAttributesTriggerFilterV1Beta1(replySource, baseEvent.Type(), nil),
resources.WithSubscriberServiceRefForTriggerV1Beta1(transformerName),
)
replyTrigger := client.CreateTriggerOrFailV1Beta1(
"reply-trigger",
resources.WithBrokerV1Beta1(broker.Name),
resources.WithAttributesTriggerFilterV1Beta1("reply-check-source", "reply-check-type", nil),
resources.WithSubscriberServiceRefForTriggerV1Beta1(loggerName),
)

t.Run("No upgrade of version", func(t *testing.T) {
event := baseEvent
Expand Down Expand Up @@ -322,37 +347,18 @@ func BrokerV1Beta1ConsumerDataPlaneTestHelper(

t.Run("Replies are accepted and delivered", func(t *testing.T) {
event := baseEvent
source := "origin-for-reply"
event.SetSource(source)
msg := []byte(`{"msg":"Transformed!"}`)
transformPod := resources.EventTransformationPod(
"transformer-pod",
"reply-check-type",
"reply-check-source",
msg,
)
client.CreatePodOrFail(transformPod, testlib.WithService("transformer-pod"))
client.WaitForServiceEndpointsOrFail("transformer-pod", 1)
transformTrigger := client.CreateTriggerOrFailV1Beta1(
"transform-trigger",
resources.WithBrokerV1Beta1(broker.Name),
resources.WithAttributesTriggerFilterV1Beta1(source, baseEvent.Type(), nil),
resources.WithSubscriberServiceRefForTriggerV1Beta1("transformer-pod"),
)

event.SetSource(replySource)
client.WaitForServiceEndpointsOrFail(transformerName, 1)

client.WaitForResourceReadyOrFail(transformTrigger.Name, testlib.TriggerTypeMeta)

replyTrigger := client.CreateTriggerOrFailV1Beta1(
"reply-trigger",
resources.WithBrokerV1Beta1(broker.Name),
resources.WithAttributesTriggerFilterV1Beta1("reply-check-source", "reply-check-type", nil),
resources.WithSubscriberServiceRefForTriggerV1Beta1(loggerName),
)
client.WaitForResourceReadyOrFail(replyTrigger.Name, testlib.TriggerTypeMeta)
client.SendEventToAddressable(source+"-sender", broker.Name, testlib.BrokerTypeMeta, event)
client.SendEventToAddressable(replySource+"-sender", broker.Name, testlib.BrokerTypeMeta, event)
transformedEventMatcher := recordevents.MatchEvent(
cetest.HasSource("reply-check-source"),
cetest.HasType("reply-check-type"),
cetest.HasData(msg),
cetest.HasData(transformMsg),
)
eventTracker.AssertAtLeast(2, transformedEventMatcher)
})
Expand Down