Skip to content

Commit

Permalink
test/ads: fix test flakyness
Browse files Browse the repository at this point in the history
PR openservicemesh#3803 introduced a mapset (backed by golang map) to slice conversion,
which does not guarantee same output ordering for the same input,
thus was making a unit test fail from time to time.

This commit forces output of the slice to be alphabetically ordered,
ensuring determinism of the output slice for the same input mapset.

Signed-off-by: Eduard Serra <[email protected]>
  • Loading branch information
eduser25 committed Jul 31, 2021
1 parent 65e567a commit 352c220
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/envoy/ads/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ var _ = Describe("Test ADS response functions", func() {
Expect(err).To(BeNil())
Expect(proxyServiceCert.Name).To(Equal(secrets.SDSCert{
Name: proxySvcAccount.String(),
CertType: secrets.ServiceCertType,
CertType: secrets.RootCertTypeForMTLSInbound,
}.String()))

serverRootCertTypeForMTLSInbound := xds_auth.Secret{}
Expand All @@ -196,7 +196,7 @@ var _ = Describe("Test ADS response functions", func() {
Expect(err).To(BeNil())
Expect(serverRootCertTypeForMTLSInbound.Name).To(Equal(secrets.SDSCert{
Name: proxySvcAccount.String(),
CertType: secrets.RootCertTypeForMTLSInbound,
CertType: secrets.ServiceCertType,
}.String()))
})
})
Expand Down Expand Up @@ -253,7 +253,7 @@ var _ = Describe("Test ADS response functions", func() {
Expect(err).To(BeNil())
Expect(proxyServiceCert.Name).To(Equal(secrets.SDSCert{
Name: proxySvcAccount.String(),
CertType: secrets.ServiceCertType,
CertType: secrets.RootCertTypeForMTLSInbound,
}.String()))

serverRootCertTypeForMTLSInbound := xds_auth.Secret{}
Expand All @@ -262,7 +262,7 @@ var _ = Describe("Test ADS response functions", func() {
Expect(err).To(BeNil())
Expect(serverRootCertTypeForMTLSInbound.Name).To(Equal(secrets.SDSCert{
Name: proxySvcAccount.String(),
CertType: secrets.RootCertTypeForMTLSInbound,
CertType: secrets.ServiceCertType,
}.String()))
})
})
Expand Down
3 changes: 3 additions & 0 deletions pkg/envoy/ads/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ads

import (
"context"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -295,6 +296,7 @@ func getRequestedResourceNamesSet(discoveryRequest *xds_discovery.DiscoveryReque
}

// getResourceSliceFromMapset is a helper to convert a mapset of resource names to a string slice
// return slice is alphabetically ordered to ensure output determinism for a given input
func getResourceSliceFromMapset(resourceMap mapset.Set) []string {
resourceSlice := []string{}
it := resourceMap.Iterator()
Expand All @@ -307,6 +309,7 @@ func getResourceSliceFromMapset(resourceMap mapset.Set) []string {
}
resourceSlice = append(resourceSlice, resString)
}
sort.Strings(resourceSlice)
return resourceSlice
}

Expand Down

0 comments on commit 352c220

Please sign in to comment.