state: adjust compare for catalog events

Document that this comparison should roughly match MatchesKey

Only sort by overrideKey or service name, but not both
Add namespace to the sort.

The client side also builds a map of these based on the namespace/node/service key, so the only order
that really matters is the ordering of register/dereigster events.
pull/9671/head
Daniel Nephin 4 years ago
parent 68ec20f66a
commit 23421e190c

@ -1651,14 +1651,26 @@ func assertDeepEqual(t *testing.T, x, y interface{}, opts ...cmp.Option) {
} }
// cmpPartialOrderEvents returns a compare option which sorts events so that // cmpPartialOrderEvents returns a compare option which sorts events so that
// all events for a particular node/service are grouped together. The sort is // all events for a particular topic are grouped together. The sort is
// stable so events with the same node/service retain their relative order. // stable so events with the same key retain their relative order.
//
// This sort should match the logic in EventPayloadCheckServiceNode.MatchesKey
// to avoid masking bugs.
var cmpPartialOrderEvents = cmp.Options{ var cmpPartialOrderEvents = cmp.Options{
cmpopts.SortSlices(func(i, j stream.Event) bool { cmpopts.SortSlices(func(i, j stream.Event) bool {
key := func(e stream.Event) string { key := func(e stream.Event) string {
csn := getPayloadCheckServiceNode(e.Payload) payload := e.Payload.(EventPayloadCheckServiceNode)
// TODO: double check this sort key is correct. csn := payload.Value
return fmt.Sprintf("%s/%s/%s/%s", e.Topic, csn.Node.Node, csn.Service.Service, e.Payload.(EventPayloadCheckServiceNode).overrideKey)
name := csn.Service.Service
if payload.overrideKey != "" {
name = payload.overrideKey
}
ns := csn.Service.EnterpriseMeta.GetNamespace()
if payload.overrideNamespace != "" {
ns = payload.overrideNamespace
}
return fmt.Sprintf("%s/%s/%s/%s", e.Topic, csn.Node.Node, ns, name)
} }
return key(i) < key(j) return key(i) < key(j)
}), }),

Loading…
Cancel
Save