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 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 { func (q *graceTerminateRSList) flushList(handler func(rsToDelete *listItem) (bool, error)) bool {
q.lock.Lock() q.lock.Lock()
defer q.lock.Unlock() defer q.lock.Unlock()

View File

@ -18,10 +18,11 @@ package ipvs
import ( import (
"fmt" "fmt"
netutils "k8s.io/utils/net"
"reflect" "reflect"
"testing" "testing"
netutils "k8s.io/utils/net"
utilipvs "k8s.io/kubernetes/pkg/util/ipvs" utilipvs "k8s.io/kubernetes/pkg/util/ipvs"
utilipvstest "k8s.io/kubernetes/pkg/util/ipvs/testing" utilipvstest "k8s.io/kubernetes/pkg/util/ipvs/testing"
) )
@ -403,18 +404,28 @@ func Test_GracefulDeleteRS(t *testing.T) {
} }
func Test_RaceTerminateRSList(t *testing.T) { func Test_RaceTerminateRSList(t *testing.T) {
ipvs := &utilipvstest.FakeIPVS{} ipvs := utilipvstest.NewFake()
gracefulTerminationManager := NewGracefulTerminationManager(ipvs) gracefulTerminationManager := NewGracefulTerminationManager(ipvs)
// run in parallel to cause the race
go func() { go func() {
for i := 1; i <= 10; i++ { for i := 1; i <= 10; i++ {
for j := 1; i <= 100; j++ { for j := 1; j <= 100; j++ {
gracefulTerminationManager.rsList.add(makeListItem(i, 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") t.Error("failed to flush entries")
} }
} }