Skip to content

Commit 575c492

Browse files
authored
Merge pull request kubernetes#93464 from knight42/fix/flaky-ep-test
test: deflake TestRecycleSlices test
2 parents 00da04b + a3b772b commit 575c492

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

pkg/controller/endpointslicemirroring/reconciler_helpers_test.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package endpointslicemirroring
1818

1919
import (
20+
"sort"
2021
"testing"
2122

2223
discovery "k8s.io/api/discovery/v1beta1"
@@ -50,8 +51,8 @@ func TestRecycleSlices(t *testing.T) {
5051
},
5152
expectedSlices: &slicesByAction{
5253
toUpdate: []*discovery.EndpointSlice{
53-
simpleEndpointSlice("baz", "10.2.3.4", discovery.AddressTypeIPv4),
5454
simpleEndpointSlice("bar", "10.1.2.3", discovery.AddressTypeIPv4),
55+
simpleEndpointSlice("baz", "10.2.3.4", discovery.AddressTypeIPv4),
5556
},
5657
},
5758
}, {
@@ -122,11 +123,19 @@ func TestRecycleSlices(t *testing.T) {
122123

123124
for _, tc := range testCases {
124125
t.Run(tc.testName, func(t *testing.T) {
125-
recycleSlices(tc.startingSlices)
126+
startingSlices := tc.startingSlices
127+
recycleSlices(startingSlices)
128+
129+
unorderedSlices := [][]*discovery.EndpointSlice{startingSlices.toCreate, startingSlices.toUpdate, startingSlices.toDelete}
130+
for _, actual := range unorderedSlices {
131+
sort.Slice(actual, func(i, j int) bool {
132+
return actual[i].Name < actual[j].Name
133+
})
134+
}
126135

127-
expectEqualSlices(t, tc.startingSlices.toCreate, tc.expectedSlices.toCreate)
128-
expectEqualSlices(t, tc.startingSlices.toUpdate, tc.expectedSlices.toUpdate)
129-
expectEqualSlices(t, tc.startingSlices.toDelete, tc.expectedSlices.toDelete)
136+
expectEqualSlices(t, startingSlices.toCreate, tc.expectedSlices.toCreate)
137+
expectEqualSlices(t, startingSlices.toUpdate, tc.expectedSlices.toUpdate)
138+
expectEqualSlices(t, startingSlices.toDelete, tc.expectedSlices.toDelete)
130139
})
131140
}
132141
}

0 commit comments

Comments
 (0)