1
// Copyright 2022 The CubeFS Authors.
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
// implied. See the License for the specific language governing
13
// permissions and limitations under the License.
21
"github.com/stretchr/testify/require"
24
func TestSelector_Base(t *testing.T) {
25
cfg := newCfg([]string{"http://127.0.0.1:8888", "http://127.0.0.1:8888"},
26
[]string{"http://127.0.0.1:8988", "http://127.0.0.1:8998"})
28
cfg.FailRetryIntervalS = 1
29
cfg.MaxFailsPeriodS = 1
32
sel, ok := s.(*selector)
33
require.Equal(t, true, ok)
34
require.NotNil(t, sel)
35
require.Equal(t, 4, len(s.GetAvailableHosts()))
38
s.SetFail("http://127.0.0.1:8988")
39
s.SetFail("http://127.0.0.1:8988")
40
s.SetFail("http://127.0.0.1:8988")
41
require.Equal(t, 3, len(s.GetAvailableHosts()))
44
for key := range sel.crackHosts {
47
require.Equal(t, 4, len(s.GetAvailableHosts()))
50
s.SetFail("http://127.0.0.1:8888")
51
s.SetFail("http://127.0.0.1:8888")
52
s.SetFail("http://127.0.0.1:8888")
53
time.Sleep(time.Millisecond * 1200)
54
require.Equal(t, 4, len(s.GetAvailableHosts()))