Skip to content

Commit

Permalink
fix flaky unit test
Browse files Browse the repository at this point in the history
Signed-off-by: 守辰 <[email protected]>
  • Loading branch information
furykerry committed Apr 1, 2024
1 parent 4a0ab2f commit 8405a40
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/controller/uniteddeployment/revision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilretry "k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/client"

appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
Expand Down Expand Up @@ -112,9 +113,16 @@ func TestRevisionManage(t *testing.T) {
g.Expect(c.List(context.TODO(), revisionList, &client.ListOptions{})).Should(gomega.BeNil())
g.Expect(len(revisionList.Items)).Should(gomega.BeEquivalentTo(1))

g.Expect(c.Get(context.TODO(), client.ObjectKey{Namespace: instance.Namespace, Name: instance.Name}, instance)).Should(gomega.BeNil())
instance.Spec.Template.StatefulSetTemplate.Labels["version"] = "v2"
g.Expect(c.Update(context.TODO(), instance)).Should(gomega.BeNil())
err = utilretry.RetryOnConflict(utilretry.DefaultRetry, func() error {
newInstance := &appsv1alpha1.UnitedDeployment{}
if err := c.Get(context.TODO(), client.ObjectKey{Namespace: instance.Namespace, Name: instance.Name}, newInstance); err != nil {
return err
}
instance.Spec.Template.StatefulSetTemplate.Labels["version"] = "v2"
return c.Update(context.TODO(), newInstance)
})

g.Expect(err).Should(gomega.BeNil())
waitReconcilerProcessFinished(g, requests, 0)

revisionList = &appsv1.ControllerRevisionList{}
Expand Down

0 comments on commit 8405a40

Please sign in to comment.