Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: deflake TestRecycleSlices test #93464

Merged
merged 1 commit into from Jul 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 14 additions & 5 deletions pkg/controller/endpointslicemirroring/reconciler_helpers_test.go
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package endpointslicemirroring

import (
"sort"
"testing"

discovery "k8s.io/api/discovery/v1beta1"
Expand Down Expand Up @@ -50,8 +51,8 @@ func TestRecycleSlices(t *testing.T) {
},
expectedSlices: &slicesByAction{
toUpdate: []*discovery.EndpointSlice{
simpleEndpointSlice("baz", "10.2.3.4", discovery.AddressTypeIPv4),
simpleEndpointSlice("bar", "10.1.2.3", discovery.AddressTypeIPv4),
simpleEndpointSlice("baz", "10.2.3.4", discovery.AddressTypeIPv4),
},
},
}, {
Expand Down Expand Up @@ -122,11 +123,19 @@ func TestRecycleSlices(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.testName, func(t *testing.T) {
recycleSlices(tc.startingSlices)
startingSlices := tc.startingSlices
recycleSlices(startingSlices)

unorderedSlices := [][]*discovery.EndpointSlice{startingSlices.toCreate, startingSlices.toUpdate, startingSlices.toDelete}
for _, actual := range unorderedSlices {
sort.Slice(actual, func(i, j int) bool {
return actual[i].Name < actual[j].Name
})
}

expectEqualSlices(t, tc.startingSlices.toCreate, tc.expectedSlices.toCreate)
expectEqualSlices(t, tc.startingSlices.toUpdate, tc.expectedSlices.toUpdate)
expectEqualSlices(t, tc.startingSlices.toDelete, tc.expectedSlices.toDelete)
expectEqualSlices(t, startingSlices.toCreate, tc.expectedSlices.toCreate)
expectEqualSlices(t, startingSlices.toUpdate, tc.expectedSlices.toUpdate)
expectEqualSlices(t, startingSlices.toDelete, tc.expectedSlices.toDelete)
})
}
}
Expand Down