Skip to content

Commit f66d2e0

Browse files
committed
steps to reproduce intermittent error
1 parent c2f1e3d commit f66d2e0

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

tests/framework/resourcemanager.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,3 +683,53 @@ func countNumberOfReadyParents(parents []v1.RouteParentStatus) int {
683683

684684
return readyCount
685685
}
686+
687+
func (rm *ResourceManager) WaitForAppsToBeReadyWithPodCount(namespace string, podCount int) error {
688+
ctx, cancel := context.WithTimeout(context.Background(), rm.TimeoutConfig.CreateTimeout)
689+
defer cancel()
690+
691+
return rm.WaitForAppsToBeReadyWithCtxWithPodCount(ctx, namespace, podCount)
692+
}
693+
694+
func (rm *ResourceManager) WaitForAppsToBeReadyWithCtxWithPodCount(ctx context.Context, namespace string, podCount int) error {
695+
if err := rm.WaitForPodsToBeReadyWithCount(ctx, namespace, podCount); err != nil {
696+
return err
697+
}
698+
699+
if err := rm.waitForHTTPRoutesToBeReady(ctx, namespace); err != nil {
700+
return err
701+
}
702+
703+
if err := rm.waitForGRPCRoutesToBeReady(ctx, namespace); err != nil {
704+
return err
705+
}
706+
707+
return rm.waitForGatewaysToBeReady(ctx, namespace)
708+
}
709+
710+
// WaitForPodsToBeReady waits for all Pods in the specified namespace to be ready or
711+
// until the provided context is cancelled.
712+
func (rm *ResourceManager) WaitForPodsToBeReadyWithCount(ctx context.Context, namespace string, count int) error {
713+
return wait.PollUntilContextCancel(
714+
ctx,
715+
500*time.Millisecond,
716+
true, /* poll immediately */
717+
func(ctx context.Context) (bool, error) {
718+
var podList core.PodList
719+
if err := rm.K8sClient.List(ctx, &podList, client.InNamespace(namespace)); err != nil {
720+
return false, err
721+
}
722+
723+
var podsReady int
724+
for _, pod := range podList.Items {
725+
for _, cond := range pod.Status.Conditions {
726+
if cond.Type == core.PodReady && cond.Status == core.ConditionTrue {
727+
podsReady++
728+
}
729+
}
730+
}
731+
732+
return podsReady == count, nil
733+
},
734+
)
735+
}

tests/suite/graceful_recovery_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("functional", "gracefu
7373
BeforeEach(func() {
7474
Expect(resourceManager.Apply([]client.Object{ns})).To(Succeed())
7575
Expect(resourceManager.ApplyFromFiles(files, ns.Name)).To(Succeed())
76-
Expect(resourceManager.WaitForAppsToBeReady(ns.Name)).To(Succeed())
76+
Expect(resourceManager.WaitForAppsToBeReadyWithPodCount(ns.Name, 2)).To(Succeed())
7777

7878
Eventually(
7979
func() error {
@@ -107,7 +107,7 @@ func runRecoveryTest(teaURL, coffeeURL, ngfPodName, containerName string, files
107107
)
108108

109109
if containerName != nginxContainerName {
110-
// Since we have already deployed resources and ran resourceManager.WaitForAppsToBeReady(ns.Name) earlier,
110+
// Since we have already deployed resources and ran resourceManager.WaitForAppsToBeReadyWithPodCount earlier,
111111
// we know that the applications are ready at this point. This could only be the case if NGF has written
112112
// statuses, which could only be the case if NGF has the leader lease. Since there is only one instance
113113
// of NGF in this test, we can be certain that this is the correct leaseholder name.
@@ -146,7 +146,7 @@ func runRecoveryTest(teaURL, coffeeURL, ngfPodName, containerName string, files
146146
Should(Succeed())
147147

148148
Expect(resourceManager.ApplyFromFiles(files, ns.Name)).To(Succeed())
149-
Expect(resourceManager.WaitForAppsToBeReady(ns.Name)).To(Succeed())
149+
Expect(resourceManager.WaitForAppsToBeReadyWithPodCount(ns.Name, 2)).To(Succeed())
150150

151151
Eventually(
152152
func() error {

0 commit comments

Comments
 (0)