0b02a48a10
Current node selection logic (in case of using SelectBySubnet): 1. selects one subnet randomly 2. selects one node randomly from the subnet 3. applies the placement NodeFilters to the node and ignore it, if doesn't match This logic is wrong: 1. Imagine that we have a subnet with two DE and one GB nodes. 2. We would like to select DE nodes 2. In case of GB node is selected (randomly) in step2, step3 will ignore the subnet, even if there are good (DE) nodes in there. Change-Id: I7673f52c89b46e0cc7b20a9b74137dc689d6c17e
44 lines
931 B
Go
44 lines
931 B
Go
// Copyright (C) 2023 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package nodeselection
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"golang.org/x/exp/slices"
|
|
)
|
|
|
|
func TestRand(t *testing.T) {
|
|
// test if we get a full permutation
|
|
|
|
t.Run("generate real permutations", func(t *testing.T) {
|
|
var numbers []uint64
|
|
c := NewRandomOrder(20)
|
|
for c.Next() {
|
|
numbers = append(numbers, c.At())
|
|
}
|
|
require.Len(t, numbers, 20)
|
|
slices.Sort(numbers)
|
|
for i := 0; i < len(numbers); i++ {
|
|
require.Equal(t, uint64(i), numbers[i])
|
|
}
|
|
})
|
|
|
|
t.Run("next always returns with false at the end", func(t *testing.T) {
|
|
c := NewRandomOrder(3)
|
|
require.True(t, c.Next())
|
|
require.True(t, c.Next())
|
|
require.True(t, c.Next())
|
|
require.False(t, c.Next())
|
|
require.False(t, c.Next())
|
|
})
|
|
|
|
t.Run("z ero size is accepted", func(t *testing.T) {
|
|
c := NewRandomOrder(0)
|
|
require.False(t, c.Next())
|
|
})
|
|
|
|
}
|