Skip to content

Commit

Permalink
tests: Add wait for function and packagerevision readiness (#3751)
Browse files Browse the repository at this point in the history
The agggregated apiserver can sometimes be slow to respond, for
example if it is polling git synchronously.  After creating a
Repository in our tests, wait for the aggregated apiserver to start
responding before returning.

This should clean up some test flakes.
  • Loading branch information
justinsb committed Jan 26, 2023
1 parent 11a17b6 commit 0632148
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions porch/test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2152,11 +2152,6 @@ func (t *PorchSuite) registerGitRepositoryF(ctx context.Context, repo, name, dir
},
})

// TODO: Replace with readiness check or similar, once we get to CRDs
// Sometimes we see "failed to list resources" here, I believe because we need to wait for the repository to be crawled.
t.Logf("HACK: sleeping for 5 seconds to allow for repository registration")
time.Sleep(5 * time.Second)

t.Cleanup(func() {
t.DeleteL(ctx, &configapi.Repository{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -2165,6 +2160,10 @@ func (t *PorchSuite) registerGitRepositoryF(ctx context.Context, repo, name, dir
},
})
})

// Make sure the repository is ready before we test to (hopefully)
// avoid flakiness.
t.waitUntilRepositoryReady(ctx, name, t.namespace)
}

type repositoryOption func(*configapi.Repository)
Expand Down Expand Up @@ -2310,6 +2309,9 @@ func (t *PorchSuite) mustNotExist(ctx context.Context, obj client.Object) {

// waitUntilRepositoryReady waits for up to 10 seconds for the repository with the
// provided name and namespace is ready, i.e. the Ready condition is true.
// It also queries for Functions and PackageRevisions, to ensure these are also
// ready - this is an artifact of the way we've implemented the aggregated apiserver,
// where the first fetch can sometimes be synchronous.
func (t *PorchSuite) waitUntilRepositoryReady(ctx context.Context, name, namespace string) {
nn := types.NamespacedName{
Name: name,
Expand All @@ -2332,6 +2334,31 @@ func (t *PorchSuite) waitUntilRepositoryReady(ctx context.Context, name, namespa
if err != nil {
t.Errorf("Repository not ready after wait: %v", innerErr)
}

// While we're using an aggregated apiserver, make sure we can query the generated objects
if err := wait.PollImmediateWithContext(ctx, time.Second, 10*time.Second, func(ctx context.Context) (bool, error) {
var revisions porchapi.PackageRevisionList
if err := t.client.List(ctx, &revisions, client.InNamespace(nn.Namespace)); err != nil {
innerErr = err
return false, nil
}
return true, nil
}); err != nil {
t.Errorf("unable to query PackageRevisions after wait: %v", innerErr)
}

// Check for functions also (until we move them to CRDs)
if err := wait.PollImmediateWithContext(ctx, time.Second, 10*time.Second, func(ctx context.Context) (bool, error) {
var functions porchapi.FunctionList
if err := t.client.List(ctx, &functions, client.InNamespace(nn.Namespace)); err != nil {
innerErr = err
return false, nil
}
return true, nil
}); err != nil {
t.Errorf("unable to query Functions after wait: %v", innerErr)
}

}

func (t *PorchSuite) waitUntilRepositoryDeleted(ctx context.Context, name, namespace string) {
Expand Down

0 comments on commit 0632148

Please sign in to comment.