Skip to content

Commit 850fd0f

Browse files
authored
Merge pull request kubernetes#2901 from jbartosik/deflake_ac_test
Make flaky assertion more verbose
2 parents 681dbf0 + 57f5882 commit 850fd0f

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

vertical-pod-autoscaler/pkg/admission-controller/logic/server_test.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ func eqPatch(a, b patchRecord) bool {
132132
return string(aJson) == string(bJson) && aErr == bErr
133133
}
134134

135+
func assertEqPatch(t *testing.T, got, want patchRecord) {
136+
assert.True(t, eqPatch(got, want), "got %+v, want: %+v", got, want)
137+
}
138+
139+
func assertPatchOneOf(t *testing.T, got patchRecord, want []patchRecord) {
140+
for _, wanted := range want {
141+
if eqPatch(got, wanted) {
142+
return
143+
}
144+
}
145+
msg := fmt.Sprintf("got: %+v, expected one of %+v", got, want)
146+
assert.Fail(t, msg)
147+
}
148+
135149
func TestGetPatchesForResourceRequest(t *testing.T) {
136150
tests := []struct {
137151
name string
@@ -389,12 +403,12 @@ func TestGetPatchesForResourceRequest_TwoReplacementResources(t *testing.T) {
389403
if assert.Equal(t, len(patches), 5) {
390404
cpuUpdate := addResourceRequestPatch(0, cpu, "1")
391405
unobtaniumUpdate := addResourceRequestPatch(0, unobtanium, "2")
392-
assert.True(t, eqPatch(patches[0], cpuUpdate) || eqPatch(patches[0], unobtaniumUpdate))
393-
assert.True(t, eqPatch(patches[1], cpuUpdate) || eqPatch(patches[1], unobtaniumUpdate))
406+
assertPatchOneOf(t, patches[0], []patchRecord{cpuUpdate, unobtaniumUpdate})
407+
assertPatchOneOf(t, patches[1], []patchRecord{cpuUpdate, unobtaniumUpdate})
394408
assert.False(t, eqPatch(patches[0], patches[1]))
395-
assert.True(t, eqPatch(patches[2], getAddEmptyAnnotationsPatch()))
396-
assert.True(t, eqPatch(patches[3], addAnnotationRequest([][]string{{cpu, unobtanium}}, request)) || eqPatch(patches[2], addAnnotationRequest([][]string{{unobtanium, cpu}}, request)))
397-
assert.True(t, eqPatch(patches[4], addVpaObservedContainersPatch([]string{})))
409+
assertEqPatch(t, patches[2], getAddEmptyAnnotationsPatch())
410+
assertEqPatch(t, patches[3], addAnnotationRequest([][]string{{cpu, unobtanium}}, request))
411+
assertEqPatch(t, patches[4], addVpaObservedContainersPatch([]string{}))
398412
}
399413
}
400414

0 commit comments

Comments
 (0)