fix flake test for ipvs graceful termination

This commit is contained in:
Antonio Ojea 2022-01-27 09:55:44 +01:00
parent 876d4e0ab0
commit 1c5d8cfdf7
2 changed files with 24 additions and 5 deletions

View File

@ -80,6 +80,14 @@ func (q *graceTerminateRSList) remove(rs *listItem) bool {
return false
}
// return the size of the list
func (q *graceTerminateRSList) len() int {
q.lock.Lock()
defer q.lock.Unlock()
return len(q.list)
}
func (q *graceTerminateRSList) flushList(handler func(rsToDelete *listItem) (bool, error)) bool {
q.lock.Lock()
defer q.lock.Unlock()

View File

@ -18,10 +18,11 @@ package ipvs
import (
"fmt"
netutils "k8s.io/utils/net"
"reflect"
"testing"
netutils "k8s.io/utils/net"
utilipvs "k8s.io/kubernetes/pkg/util/ipvs"
utilipvstest "k8s.io/kubernetes/pkg/util/ipvs/testing"
)
@ -403,18 +404,28 @@ func Test_GracefulDeleteRS(t *testing.T) {
}
func Test_RaceTerminateRSList(t *testing.T) {
ipvs := &utilipvstest.FakeIPVS{}
ipvs := utilipvstest.NewFake()
gracefulTerminationManager := NewGracefulTerminationManager(ipvs)
// run in parallel to cause the race
go func() {
for i := 1; i <= 10; i++ {
for j := 1; i <= 100; j++ {
gracefulTerminationManager.rsList.add(makeListItem(i, j))
for j := 1; j <= 100; j++ {
item := makeListItem(i, j)
gracefulTerminationManager.rsList.add(item)
}
}
}()
if !gracefulTerminationManager.rsList.flushList(gracefulTerminationManager.deleteRsFunc) {
// wait until the list has some elements
for gracefulTerminationManager.rsList.len() < 20 {
}
// fake the handler to avoid the check against the IPVS virtual servers
fakeHandler := func(rsToDelete *listItem) (bool, error) {
return true, nil
}
if !gracefulTerminationManager.rsList.flushList(fakeHandler) {
t.Error("failed to flush entries")
}
}