From fef771d0ca79b3d58d2da752be317e24bcdb2954 Mon Sep 17 00:00:00 2001 From: Jerop Date: Thu, 2 Sep 2021 15:44:35 -0400 Subject: [PATCH] Poll for the status of Runs Today, each custom tasks implementation copies over the wait.go file to poll the status of resources for testing. This makes it hard to maintain over time. The only added function in the custom tasks testing is the polling for the status of Runs. This change adds the function to poll for the status of Runs so that this can be reused across all custom tasks testing. --- test/wait.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/wait.go b/test/wait.go index 41ca394d8bf..76c0fba9b09 100644 --- a/test/wait.go +++ b/test/wait.go @@ -95,6 +95,26 @@ func WaitForTaskRunState(ctx context.Context, c *clients, name string, inState C }) } +// WaitForRunState polls the status of the Run called name from client every +// interval until inState returns `true` indicating it is done, returns an +// error or timeout. desc will be used to name the metric that is emitted to +// track how long it took for name to get into the state checked by inState. +func WaitForRunState(ctx context.Context, c *clients, name string, polltimeout time.Duration, inState ConditionAccessorFn, desc string) error { + metricName := fmt.Sprintf("WaitForRunState/%s/%s", name, desc) + _, span := trace.StartSpan(context.Background(), metricName) + defer span.End() + + ctx, cancel := context.WithTimeout(ctx, polltimeout) + defer cancel() + return pollImmediateWithContext(ctx, func() (bool, error) { + r, err := c.RunClient.Get(ctx, name, metav1.GetOptions{}) + if err != nil { + return true, err + } + return inState(&r.Status) + }) +} + // WaitForDeploymentState polls the status of the Deployment called name // from client every interval until inState returns `true` indicating it is done, // returns an error or timeout. desc will be used to name the metric that is emitted to