Skip to content

Commit

Permalink
Merge pull request #5215 from sbueringer/pr-fix-flakey-patch-test
Browse files Browse the repository at this point in the history
🐛  fix flaky TestPatchHelper test
  • Loading branch information
k8s-ci-robot authored Sep 8, 2021
2 parents 494b8cc + 18dc650 commit d56c775
Showing 1 changed file with 41 additions and 23 deletions.
64 changes: 41 additions & 23 deletions util/patch/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ func TestPatchHelper(t *testing.T) {
g.Expect(patcher.Patch(ctx, obj)).To(Succeed())

t.Log("Validating the object has been updated")
g.Eventually(func() bool {
g.Eventually(func() clusterv1.Conditions {
objAfter := obj.DeepCopy()
if err := env.Get(ctx, key, objAfter); err != nil {
return false
return clusterv1.Conditions{}
}
return cmp.Equal(obj.Status.Conditions, objAfter.Status.Conditions)
}, timeout).Should(BeTrue())
return objAfter.Status.Conditions
}, timeout).Should(conditions.MatchConditions(obj.Status.Conditions))
})

t.Run("should recover if there is a resolvable conflict", func(t *testing.T) {
Expand Down Expand Up @@ -261,11 +261,19 @@ func TestPatchHelper(t *testing.T) {

testConditionCopy := conditions.Get(objCopy, "TestCondition")
testConditionAfter := conditions.Get(objAfter, "TestCondition")
ok, err := conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
if err != nil || !ok {
return false
}

readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
ok, err = conditions.MatchCondition(*readyBefore).Match(*readyAfter)
if err != nil || !ok {
return false
}

return cmp.Equal(testConditionCopy, testConditionAfter) && cmp.Equal(readyBefore, readyAfter)
return true
}, timeout).Should(BeTrue())
})

Expand Down Expand Up @@ -319,12 +327,19 @@ func TestPatchHelper(t *testing.T) {

testConditionCopy := conditions.Get(objCopy, "TestCondition")
testConditionAfter := conditions.Get(objAfter, "TestCondition")
ok, err := conditions.MatchCondition(*testConditionCopy).Match(*testConditionAfter)
if err != nil || !ok {
return false
}

readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)
ok, err = conditions.MatchCondition(*readyBefore).Match(*readyAfter)
if err != nil || !ok {
return false
}

return cmp.Equal(testConditionCopy, testConditionAfter) && cmp.Equal(readyBefore, readyAfter) &&
obj.Spec.Paused == objAfter.Spec.Paused &&
return obj.Spec.Paused == objAfter.Spec.Paused &&
obj.Spec.ControlPlaneEndpoint == objAfter.Spec.ControlPlaneEndpoint &&
obj.Status.Phase == objAfter.Status.Phase
}, timeout).Should(BeTrue(), cmp.Diff(obj, objAfter))
Expand Down Expand Up @@ -373,8 +388,15 @@ func TestPatchHelper(t *testing.T) {
if err := env.Get(ctx, key, objAfter); err != nil {
return false
}
ok, _ := ContainElement(objCopy.Status.Conditions[0]).Match(objAfter.Status.Conditions)
return ok

for _, afterCondition := range objAfter.Status.Conditions {
ok, err := conditions.MatchCondition(objCopy.Status.Conditions[0]).Match(afterCondition)
if err == nil && ok {
return true
}
}

return false
}, timeout).Should(BeTrue())
})

Expand Down Expand Up @@ -416,17 +438,15 @@ func TestPatchHelper(t *testing.T) {
g.Expect(patcher.Patch(ctx, obj, WithOwnedConditions{Conditions: []clusterv1.ConditionType{clusterv1.ReadyCondition}})).To(Succeed())

t.Log("Validating the object has been updated")
g.Eventually(func() bool {
readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
g.Eventually(func() clusterv1.Condition {
objAfter := obj.DeepCopy()
if err := env.Get(ctx, key, objAfter); err != nil {
return false
return clusterv1.Condition{}
}

readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)

return cmp.Equal(readyBefore, readyAfter)
}, timeout).Should(BeTrue())
return *conditions.Get(objAfter, clusterv1.ReadyCondition)
}, timeout).Should(conditions.MatchCondition(*readyBefore))
})

t.Run("should not return an error if there is an unresolvable conflict when force overwrite is enabled", func(t *testing.T) {
Expand Down Expand Up @@ -467,17 +487,15 @@ func TestPatchHelper(t *testing.T) {
g.Expect(patcher.Patch(ctx, obj, WithForceOverwriteConditions{})).To(Succeed())

t.Log("Validating the object has been updated")
g.Eventually(func() bool {
readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
g.Eventually(func() clusterv1.Condition {
objAfter := obj.DeepCopy()
if err := env.Get(ctx, key, objAfter); err != nil {
return false
return clusterv1.Condition{}
}

readyBefore := conditions.Get(obj, clusterv1.ReadyCondition)
readyAfter := conditions.Get(objAfter, clusterv1.ReadyCondition)

return cmp.Equal(readyBefore, readyAfter)
}, timeout).Should(BeTrue())
return *conditions.Get(objAfter, clusterv1.ReadyCondition)
}, timeout).Should(conditions.MatchCondition(*readyBefore))
})
})
})
Expand Down

0 comments on commit d56c775

Please sign in to comment.