Skip to content

Commit

Permalink
Poll for the status of Runs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jerop authored and tekton-robot committed Sep 4, 2021
1 parent f041ef5 commit fef771d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fef771d

Please sign in to comment.