New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed code to improve output messages on error for files under test/e2e/apps #109944
Changes from all commits
a8198b1
870d5d2
f603dfa
5d0ec1d
92b15ca
f6ab8f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -261,7 +261,9 @@ var _ = SIGDescribe("CronJob", func() { | |
ginkgo.By("Ensuring job was deleted") | ||
_, err = e2ejob.GetJob(f.ClientSet, f.Namespace.Name, job.Name) | ||
framework.ExpectError(err) | ||
framework.ExpectEqual(apierrors.IsNotFound(err), true) | ||
if !apierrors.IsNotFound(err) { | ||
framework.Failf("Failed to delete %s cronjob in namespace %s", cronJob.Name, f.Namespace.Name) | ||
} | ||
|
||
ginkgo.By("Ensuring the job is not in the cronjob active list") | ||
err = waitForJobNotActive(f.ClientSet, f.Namespace.Name, cronJob.Name, job.Name) | ||
|
@@ -374,10 +376,14 @@ var _ = SIGDescribe("CronJob", func() { | |
for sawAnnotations := false; !sawAnnotations; { | ||
select { | ||
case evt, ok := <-cjWatch.ResultChan(): | ||
framework.ExpectEqual(ok, true, "watch channel should not close") | ||
if !ok { | ||
framework.Fail("watch channel should not close") | ||
} | ||
framework.ExpectEqual(evt.Type, watch.Modified) | ||
watchedCronJob, isCronJob := evt.Object.(*batchv1.CronJob) | ||
framework.ExpectEqual(isCronJob, true, fmt.Sprintf("expected CronJob, got %T", evt.Object)) | ||
if !isCronJob { | ||
framework.Failf("expected CronJob, got %T", evt.Object) | ||
} | ||
if watchedCronJob.Annotations["patched"] == "true" { | ||
framework.Logf("saw patched and updated annotations") | ||
sawAnnotations = true | ||
|
@@ -403,7 +409,9 @@ var _ = SIGDescribe("CronJob", func() { | |
[]byte(`{"metadata":{"annotations":{"patchedstatus":"true"}},"status":`+string(cjStatusJSON)+`}`), | ||
metav1.PatchOptions{}, "status") | ||
framework.ExpectNoError(err) | ||
framework.ExpectEqual(patchedStatus.Status.LastScheduleTime.Equal(&now1), true, "patched object should have the applied lastScheduleTime status") | ||
if !patchedStatus.Status.LastScheduleTime.Equal(&now1) { | ||
framework.Failf("patched object should have the applied lastScheduleTime %#v, got %#v instead", cjStatus.LastScheduleTime, patchedStatus.Status.LastScheduleTime) | ||
} | ||
framework.ExpectEqual(patchedStatus.Annotations["patchedstatus"], "true", "patched object should have the applied annotation") | ||
|
||
ginkgo.By("updating /status") | ||
|
@@ -420,7 +428,9 @@ var _ = SIGDescribe("CronJob", func() { | |
return err | ||
}) | ||
framework.ExpectNoError(err) | ||
framework.ExpectEqual(updatedStatus.Status.LastScheduleTime.Equal(&now2), true, fmt.Sprintf("updated object status expected to have updated lastScheduleTime %#v, got %#v", statusToUpdate.Status.LastScheduleTime, updatedStatus.Status.LastScheduleTime)) | ||
if !updatedStatus.Status.LastScheduleTime.Equal(&now2) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how is this working then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, the commits need to be squashed |
||
framework.Failf("updated object status expected to have updated lastScheduleTime %#v, got %#v", statusToUpdate.Status.LastScheduleTime, updatedStatus.Status.LastScheduleTime) | ||
} | ||
|
||
ginkgo.By("get /status") | ||
cjResource := schema.GroupVersionResource{Group: "batch", Version: cjVersion, Resource: "cronjobs"} | ||
|
@@ -433,7 +443,9 @@ var _ = SIGDescribe("CronJob", func() { | |
// CronJob resource delete operations | ||
expectFinalizer := func(cj *batchv1.CronJob, msg string) { | ||
framework.ExpectNotEqual(cj.DeletionTimestamp, nil, fmt.Sprintf("expected deletionTimestamp, got nil on step: %q, cronjob: %+v", msg, cj)) | ||
framework.ExpectEqual(len(cj.Finalizers) > 0, true, fmt.Sprintf("expected finalizers on cronjob, got none on step: %q, cronjob: %+v", msg, cj)) | ||
if len(cj.Finalizers) == 0 { | ||
framework.Failf("expected finalizers on cronjob, got none on step: %q, cronjob: %+v", msg, cj) | ||
} | ||
} | ||
|
||
ginkgo.By("deleting") | ||
|
@@ -447,7 +459,9 @@ var _ = SIGDescribe("CronJob", func() { | |
if err == nil { | ||
expectFinalizer(cj, "deleting cronjob") | ||
} else { | ||
framework.ExpectEqual(apierrors.IsNotFound(err), true, fmt.Sprintf("expected 404, got %v", err)) | ||
if !apierrors.IsNotFound(err) { | ||
framework.Failf("expected 404, got %v", err) | ||
} | ||
} | ||
|
||
ginkgo.By("deleting a collection") | ||
|
@@ -456,7 +470,10 @@ var _ = SIGDescribe("CronJob", func() { | |
cjs, err = cjClient.List(context.TODO(), metav1.ListOptions{LabelSelector: "special-label=" + f.UniqueName}) | ||
framework.ExpectNoError(err) | ||
// Should have <= 2 items since some cronjobs might not have been deleted yet due to finalizers | ||
framework.ExpectEqual(len(cjs.Items) <= 2, true, "filtered list should be <= 2") | ||
if len(cjs.Items) > 2 { | ||
framework.Logf("got unexpected filtered list: %v", cjs.Items) | ||
framework.Fail("filtered list should be <= 2") | ||
rafadc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
// Validate finalizers | ||
for _, cj := range cjs.Items { | ||
expectFinalizer(&cj, "deleting cronjob collection") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -317,7 +317,9 @@ var _ = SIGDescribe("DisruptionController", func() { | |
if c.shouldDeny { | ||
err = cs.CoreV1().Pods(ns).EvictV1(context.TODO(), e) | ||
framework.ExpectError(err, "pod eviction should fail") | ||
framework.ExpectEqual(apierrors.HasStatusCause(err, policyv1.DisruptionBudgetCause), true, "pod eviction should fail with DisruptionBudget cause") | ||
if !apierrors.HasStatusCause(err, policyv1.DisruptionBudgetCause) { | ||
framework.Fail("pod eviction should fail with DisruptionBudget cause") | ||
} | ||
} else { | ||
// Only wait for running pods in the "allow" case | ||
// because one of shouldDeny cases relies on the | ||
|
@@ -361,7 +363,9 @@ var _ = SIGDescribe("DisruptionController", func() { | |
} | ||
err = cs.CoreV1().Pods(ns).EvictV1(context.TODO(), e) | ||
framework.ExpectError(err, "pod eviction should fail") | ||
framework.ExpectEqual(apierrors.HasStatusCause(err, policyv1.DisruptionBudgetCause), true, "pod eviction should fail with DisruptionBudget cause") | ||
if !apierrors.HasStatusCause(err, policyv1.DisruptionBudgetCause) { | ||
framework.Failf("pod eviction should fail with DisruptionBudget cause. The error was \"%v\"", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the error here in case of failure too |
||
} | ||
|
||
ginkgo.By("Updating the pdb to allow a pod to be evicted") | ||
updatePDBOrDie(cs, ns, defaultName, func(pdb *policyv1.PodDisruptionBudget) *policyv1.PodDisruptionBudget { | ||
|
@@ -399,7 +403,9 @@ var _ = SIGDescribe("DisruptionController", func() { | |
} | ||
err = cs.CoreV1().Pods(ns).EvictV1(context.TODO(), e) | ||
framework.ExpectError(err, "pod eviction should fail") | ||
framework.ExpectEqual(apierrors.HasStatusCause(err, policyv1.DisruptionBudgetCause), true, "pod eviction should fail with DisruptionBudget cause") | ||
if !apierrors.HasStatusCause(err, policyv1.DisruptionBudgetCause) { | ||
framework.Failf("pod eviction should fail with DisruptionBudget cause. The error was \"%v\"", err) | ||
} | ||
|
||
ginkgo.By("Deleting the pdb to allow a pod to be evicted") | ||
deletePDBOrDie(cs, ns, defaultName) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,7 +163,9 @@ var _ = SIGDescribe("ReplicationController", func() { | |
return true, nil | ||
}) | ||
framework.ExpectNoError(err, "Wait until condition with watch events should not return an error") | ||
framework.ExpectEqual(eventFound, true, "failed to find RC %v event", watch.Added) | ||
if !eventFound { | ||
framework.Failf("failed to find RC %v event", watch.Added) | ||
} | ||
|
||
ginkgo.By("waiting for available Replicas") | ||
eventFound = false | ||
|
@@ -186,7 +188,9 @@ var _ = SIGDescribe("ReplicationController", func() { | |
return true, nil | ||
}) | ||
framework.ExpectNoError(err, "Wait for condition with watch events should not return an error") | ||
framework.ExpectEqual(eventFound, true, "RC has not reached ReadyReplicas count of %v", testRcInitialReplicaCount) | ||
if !eventFound { | ||
framework.Failf("RC has not reached ReadyReplicas count of %v", testRcInitialReplicaCount) | ||
} | ||
|
||
rcLabelPatchPayload, err := json.Marshal(v1.ReplicationController{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
|
@@ -212,7 +216,9 @@ var _ = SIGDescribe("ReplicationController", func() { | |
return true, nil | ||
}) | ||
framework.ExpectNoError(err, "Wait until condition with watch events should not return an error") | ||
framework.ExpectEqual(eventFound, true, "failed to find RC %v event", watch.Added) | ||
if !eventFound { | ||
framework.Failf("failed to find RC %v event", watch.Added) | ||
} | ||
|
||
rcStatusPatchPayload, err := json.Marshal(map[string]interface{}{ | ||
"status": map[string]interface{}{ | ||
|
@@ -240,7 +246,9 @@ var _ = SIGDescribe("ReplicationController", func() { | |
return true, nil | ||
}) | ||
framework.ExpectNoError(err, "Wait until condition with watch events should not return an error") | ||
framework.ExpectEqual(eventFound, true, "failed to find RC %v event", watch.Added) | ||
if !eventFound { | ||
framework.Failf("failed to find RC %v event", watch.Added) | ||
} | ||
|
||
ginkgo.By("waiting for available Replicas") | ||
_, err = watchUntilWithoutRetry(context.TODO(), retryWatcher, func(watchEvent watch.Event) (bool, error) { | ||
|
@@ -259,7 +267,9 @@ var _ = SIGDescribe("ReplicationController", func() { | |
return true, nil | ||
}) | ||
framework.ExpectNoError(err, "Failed to find updated ready replica count") | ||
framework.ExpectEqual(eventFound, true, "Failed to find updated ready replica count") | ||
if !eventFound { | ||
framework.Fail("Failed to find updated ready replica count") | ||
} | ||
|
||
ginkgo.By("fetching ReplicationController status") | ||
rcStatusUnstructured, err := dc.Resource(rcResource).Namespace(testRcNamespace).Get(context.TODO(), testRcName, metav1.GetOptions{}, "status") | ||
|
@@ -294,7 +304,9 @@ var _ = SIGDescribe("ReplicationController", func() { | |
return true, nil | ||
}) | ||
framework.ExpectNoError(err, "Wait until condition with watch events should not return an error") | ||
framework.ExpectEqual(eventFound, true, "failed to find RC %v event", watch.Added) | ||
if !eventFound { | ||
framework.Failf("failed to find RC %v event", watch.Added) | ||
} | ||
|
||
ginkgo.By("waiting for ReplicationController's scale to be the max amount") | ||
eventFound = false | ||
|
@@ -315,7 +327,9 @@ var _ = SIGDescribe("ReplicationController", func() { | |
return true, nil | ||
}) | ||
framework.ExpectNoError(err, "Wait until condition with watch events should not return an error") | ||
framework.ExpectEqual(eventFound, true, "Failed to find updated ready replica count") | ||
if !eventFound { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this condition needed at all? We are not setting eventFound in the previous block. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It gets initialized as false in line 312 and set to true inside the callback function in line 326, so this check seems legitimate to me. |
||
framework.Fail("Failed to find updated ready replica count") | ||
} | ||
|
||
// Get the ReplicationController | ||
ginkgo.By("fetching ReplicationController; ensuring that it's patched") | ||
|
@@ -345,12 +359,16 @@ var _ = SIGDescribe("ReplicationController", func() { | |
return true, nil | ||
}) | ||
framework.ExpectNoError(err, "Wait until condition with watch events should not return an error") | ||
framework.ExpectEqual(eventFound, true, "failed to find RC %v event", watch.Added) | ||
if !eventFound { | ||
framework.Failf("failed to find RC %v event", watch.Added) | ||
} | ||
|
||
ginkgo.By("listing all ReplicationControllers") | ||
rcs, err := f.ClientSet.CoreV1().ReplicationControllers("").List(context.TODO(), metav1.ListOptions{LabelSelector: "test-rc-static=true"}) | ||
framework.ExpectNoError(err, "failed to list ReplicationController") | ||
framework.ExpectEqual(len(rcs.Items) > 0, true) | ||
if len(rcs.Items) == 0 { | ||
framework.Fail("Expected to find a ReplicationController but none was found") | ||
} | ||
|
||
ginkgo.By("checking that ReplicationController has expected values") | ||
foundRc := false | ||
|
@@ -362,7 +380,10 @@ var _ = SIGDescribe("ReplicationController", func() { | |
foundRc = true | ||
} | ||
} | ||
framework.ExpectEqual(foundRc, true) | ||
if !foundRc { | ||
framework.Logf("Got unexpected replication controller list %v", rcs.Items) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following the suggestion before I logged this list too and made the message a bit more descriptive |
||
framework.Failf("could not find ReplicationController %s", testRcName) | ||
} | ||
|
||
// Delete ReplicationController | ||
ginkgo.By("deleting ReplicationControllers by collection") | ||
|
@@ -382,7 +403,9 @@ var _ = SIGDescribe("ReplicationController", func() { | |
return true, nil | ||
}) | ||
framework.ExpectNoError(err, "Wait until condition with watch events should not return an error") | ||
framework.ExpectEqual(eventFound, true, "failed to find RC %v event", watch.Added) | ||
if !eventFound { | ||
framework.Failf("failed to find RC %v event", watch.Added) | ||
} | ||
|
||
return actualWatchEvents | ||
}, func() (err error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I am assuming that the intent here was to do the equal comparison with
patchedStatus.Status.LastScheduleTime.Equal
, either to exercise that function or because it does something special thatframework.ExpectEqual
wouldn't do.Either way, not changing the logic of the test makes sense, so 👍