cubefs

Форк
0
/
selector_test.go 
57 строк · 1.6 Кб
1
// Copyright 2022 The CubeFS Authors.
2
//
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
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
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.
14

15
package rpc
16

17
import (
18
	"testing"
19
	"time"
20

21
	"github.com/stretchr/testify/require"
22
)
23

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"})
27
	cfg.HostTryTimes = 3
28
	cfg.FailRetryIntervalS = 1
29
	cfg.MaxFailsPeriodS = 1
30
	s := newSelector(cfg)
31

32
	sel, ok := s.(*selector)
33
	require.Equal(t, true, ok)
34
	require.NotNil(t, sel)
35
	require.Equal(t, 4, len(s.GetAvailableHosts()))
36

37
	// test set fail
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()))
42

43
	// test enable host
44
	for key := range sel.crackHosts {
45
		sel.enableHost(key)
46
	}
47
	require.Equal(t, 4, len(s.GetAvailableHosts()))
48

49
	// test detect
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()))
55

56
	s.Close()
57
}
58

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.