Fix group checker ut (#21038) (#21067)

Signed-off-by: longjiquan <jiquan.long@zilliz.com>

Signed-off-by: longjiquan <jiquan.long@zilliz.com>

Signed-off-by: longjiquan <jiquan.long@zilliz.com>
pull/21083/head
Jiquan Long 2022-12-08 19:43:23 +08:00 committed by GitHub
parent 368686e149
commit a334853475
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -51,6 +51,7 @@ func (gc *GroupChecker) init() {
// work is the main procedure logic
func (gc *GroupChecker) work() {
gc.t = time.NewTicker(gc.d)
defer gc.t.Stop()
var name string
var ts time.Time

View File

@ -28,7 +28,8 @@ func TestGroupChecker(t *testing.T) {
signal := make(chan []string, 1)
// 10ms period which set before is too short
// change 10ms to 500ms to ensure the the group checker schedule after the second value stored
gc1 := GetGroupChecker(groupName, 500*time.Millisecond, func(list []string) {
duration := 500 * time.Millisecond
gc1 := GetGroupChecker(groupName, duration, func(list []string) {
signal <- list
})
gc1.Check("1")
@ -37,14 +38,16 @@ func TestGroupChecker(t *testing.T) {
})
gc2.Check("2")
assert.Equal(t, 500*time.Millisecond, gc2.d)
assert.Equal(t, duration, gc2.d)
list := <-signal
assert.ElementsMatch(t, []string{"1", "2"}, list)
assert.Eventually(t, func() bool {
list := <-signal
return len(list) == 2
}, duration*3, duration)
gc2.Remove("2")
list = <-signal
list := <-signal
assert.ElementsMatch(t, []string{"1"}, list)
assert.NotPanics(t, func() {