[#213] netmap: Do not append not twice if selector is unnamed

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2020-11-27 12:20:06 +03:00 committed by Leonard Lyubich
parent ea6b6adfe0
commit 4e65fa41b8
2 changed files with 28 additions and 0 deletions

View file

@ -68,6 +68,8 @@ func (m *Netmap) GetContainerNodes(p *PlacementPolicy, pivot []byte) (ContainerN
for _, s := range p.Selectors() { for _, s := range p.Selectors() {
result[i] = append(result[i], flattenNodes(c.Selections[s.Name()])...) result[i] = append(result[i], flattenNodes(c.Selections[s.Name()])...)
} }
continue
} }
nodes, ok := c.Selections[r.Selector()] nodes, ok := c.Selections[r.Selector()]

View file

@ -119,6 +119,32 @@ func TestPlacementPolicy_LowerBound(t *testing.T) {
require.Equal(t, 3, len(v.Flatten())) 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) { func TestPlacementPolicy_ProcessSelectors(t *testing.T) {
p := newPlacementPolicy(2, nil, p := newPlacementPolicy(2, nil,
[]*Selector{ []*Selector{