From 4e65fa41b8eb6cd24bcf8012a57c552f24f02078 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 27 Nov 2020 12:20:06 +0300 Subject: [PATCH] [#213] netmap: Do not append not twice if selector is unnamed Signed-off-by: Evgenii Stratonikov --- pkg/netmap/netmap.go | 2 ++ pkg/netmap/selector_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/pkg/netmap/netmap.go b/pkg/netmap/netmap.go index 95e823b..e8ea647 100644 --- a/pkg/netmap/netmap.go +++ b/pkg/netmap/netmap.go @@ -68,6 +68,8 @@ func (m *Netmap) GetContainerNodes(p *PlacementPolicy, pivot []byte) (ContainerN for _, s := range p.Selectors() { result[i] = append(result[i], flattenNodes(c.Selections[s.Name()])...) } + + continue } nodes, ok := c.Selections[r.Selector()] diff --git a/pkg/netmap/selector_test.go b/pkg/netmap/selector_test.go index b1cf378..20f5beb 100644 --- a/pkg/netmap/selector_test.go +++ b/pkg/netmap/selector_test.go @@ -119,6 +119,32 @@ func TestPlacementPolicy_LowerBound(t *testing.T) { require.Equal(t, 3, len(v.Flatten())) } +func TestIssue213(t *testing.T) { + p := newPlacementPolicy(1, + []*Replica{ + newReplica(4, ""), + }, + []*Selector{ + newSelector("", "", ClauseDistinct, 4, "LOC_EU"), + }, + []*Filter{ + newFilter("LOC_EU", "Location", "Europe", OpEQ), + }) + nodes := []NodeInfo{ + nodeInfoFromAttributes("Location", "Europe", "Country", "Russia", "City", "Moscow"), + nodeInfoFromAttributes("Location", "Europe", "Country", "Russia", "City", "Saint-Petersburg"), + nodeInfoFromAttributes("Location", "Europe", "Country", "Sweden", "City", "Stockholm"), + nodeInfoFromAttributes("Location", "Europe", "Country", "Finalnd", "City", "Helsinki"), + } + + nm, err := NewNetmap(NodesFromInfo(nodes)) + require.NoError(t, err) + + v, err := nm.GetContainerNodes(p, nil) + require.NoError(t, err) + require.Equal(t, 4, len(v.Flatten())) +} + func TestPlacementPolicy_ProcessSelectors(t *testing.T) { p := newPlacementPolicy(2, nil, []*Selector{