Skip to content

Commit

Permalink
Merge pull request GoogleCloudPlatform#1203 from justinsb/more_e2e_lo…
Browse files Browse the repository at this point in the history
…gging

tests: Add more logging in e2e tests
  • Loading branch information
google-oss-prow[bot] authored Feb 28, 2024
2 parents 8313dcc + a2b358d commit cfe60e2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ func testDriftCorrection(ctx context.Context, t *testing.T, testContext testrunn
// of this test that the right events are recorded.
testcontroller.DeleteAllEventsForUnstruct(t, kubeClient, testUnstruct)

t.Logf("testDriftCorrection: deleting kube object %v", testUnstruct)
if err := resourceContext.Delete(ctx, t, testUnstruct, systemContext.TFProvider, systemContext.Manager.GetClient(), systemContext.SMLoader, systemContext.DCLConfig, systemContext.DCLConverter); err != nil {
t.Fatalf("error deleting: %v", err)
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/test/controller/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,19 @@ func isTransientError(t *testing.T, err error) bool {
}

// RunReconcilerAssertResults asserts the expected state of the reconciler run.
func RunReconcilerAssertResults(ctx context.Context, t *testing.T, reconciler reconcile.Reconciler, objectMeta v1.ObjectMeta,
func RunReconcilerAssertResults(ctx context.Context, t *testing.T, reconciler reconcile.Reconciler,
kind string, objectMeta v1.ObjectMeta,
expectedResult reconcile.Result, expectedErrorRegex *regexp.Regexp) {
attempt := 0
tryAgain:
attempt++
t.Helper()
startTime := time.Now()
t.Logf("starting reconcile for %v:%v/%v", kind, objectMeta.Namespace, objectMeta.Name)
reconcileRequest := reconcile.Request{NamespacedName: k8s.GetNamespacedName(objectMeta.GetObjectMeta())}
result, err := reconciler.Reconcile(ctx, reconcileRequest)

t.Logf("reconcile for %v:%v/%v took %v, result was (%v, %v)",
kind, objectMeta.Namespace, objectMeta.Name, time.Since(startTime), result, err)
// Retry if we see a "transient" error (up to our retry limit)
if err != nil {
if isTransientError(t, err) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/controller/reconciler/testreconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (r *TestReconciler) Reconcile(ctx context.Context, unstruct *unstructured.U
func (r *TestReconciler) ReconcileObjectMeta(ctx context.Context, om metav1.ObjectMeta, kind string, expectedResult reconcile.Result, expectedErrorRegex *regexp.Regexp) {
r.t.Helper()
reconciler := r.NewReconcilerForKind(kind)
testcontroller.RunReconcilerAssertResults(ctx, r.t, reconciler, om, expectedResult, expectedErrorRegex)
testcontroller.RunReconcilerAssertResults(ctx, r.t, reconciler, kind, om, expectedResult, expectedErrorRegex)
}

// Creates and reconciles all unstructureds in the unstruct list. Returns a cleanup function that should be defered immediately after calling this function.
Expand Down

0 comments on commit cfe60e2

Please sign in to comment.