From 02696f2ef4645c4ef3909775c6b9e000a213dce2 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Fri, 3 Jul 2020 12:00:17 +0200 Subject: [PATCH] =?UTF-8?q?cloudevent:=20make=20sure=20we=20enter=20the=20?= =?UTF-8?q?channel=20before=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … returning. This effectively wait for the goroutine to be schedule before getting out of `SendCloudEventWithRetries`. That way we are sure the "sending cloud event" goroutine is scheduled. This doesn't wait for `ceClient.Send` to execute, just making sure we got in the goroutine. This should fix flaky tests observed during release pipeline runs. Signed-off-by: Vincent Demeester --- pkg/reconciler/events/cloudevent/cloud_event_controller.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/reconciler/events/cloudevent/cloud_event_controller.go b/pkg/reconciler/events/cloudevent/cloud_event_controller.go index 8d6db1d13d2..f7b5a6d1f9f 100644 --- a/pkg/reconciler/events/cloudevent/cloud_event_controller.go +++ b/pkg/reconciler/events/cloudevent/cloud_event_controller.go @@ -137,7 +137,9 @@ func SendCloudEventWithRetries(ctx context.Context, object runtime.Object) error return err } + wasIn := make(chan error) go func() { + wasIn <- nil if result := ceClient.Send(cloudevents.ContextWithRetriesExponentialBackoff(ctx, 10*time.Millisecond, 10), *event); !cloudevents.IsACK(result) { logger.Warnf("Failed to send cloudevent: %s", result.Error()) recorder := controller.GetEventRecorder(ctx) @@ -148,5 +150,5 @@ func SendCloudEventWithRetries(ctx context.Context, object runtime.Object) error } }() - return nil + return <-wasIn }