set node poll interval to 10ms in UT

Signed-off-by: pacoxu <paco.xu@daocloud.io>
This commit is contained in:
pacoxu 2021-02-04 16:41:24 +08:00
parent 074a517720
commit cef6e81fb3
2 changed files with 20 additions and 4 deletions

View File

@ -76,6 +76,10 @@ const (
updateMaxRetries = 10
)
// nodePollInterval is used in listing node
// This is a variable instead of a const to enable testing.
var nodePollInterval = 10 * time.Second
// CIDRAllocator is an interface implemented by things that know how
// to allocate/occupy/recycle CIDR for nodes.
type CIDRAllocator interface {
@ -123,7 +127,7 @@ func listNodes(kubeClient clientset.Interface) (*v1.NodeList, error) {
var nodeList *v1.NodeList
// We must poll because apiserver might not be up. This error causes
// controller manager to restart.
if pollErr := wait.Poll(10*time.Second, apiserverStartupGracePeriod, func() (bool, error) {
if pollErr := wait.Poll(nodePollInterval, apiserverStartupGracePeriod, func() (bool, error) {
var err error
nodeList, err = kubeClient.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{
FieldSelector: fields.Everything().String(),

View File

@ -32,9 +32,7 @@ import (
"k8s.io/kubernetes/pkg/controller/testutil"
)
const (
nodePollInterval = 100 * time.Millisecond
)
const testNodePollInterval = 10 * time.Millisecond
var alwaysReady = func() bool { return true }
@ -320,6 +318,13 @@ func TestOccupyPreExistingCIDR(t *testing.T) {
}
func TestAllocateOrOccupyCIDRSuccess(t *testing.T) {
// Non-parallel test (overrides global var)
oldNodePollInterval := nodePollInterval
nodePollInterval = testNodePollInterval
defer func() {
nodePollInterval = oldNodePollInterval
}()
// all tests operate on a single node
testCases := []testCase{
{
@ -700,6 +705,13 @@ type releaseTestCase struct {
}
func TestReleaseCIDRSuccess(t *testing.T) {
// Non-parallel test (overrides global var)
oldNodePollInterval := nodePollInterval
nodePollInterval = testNodePollInterval
defer func() {
nodePollInterval = oldNodePollInterval
}()
testCases := []releaseTestCase{
{
description: "Correctly release preallocated CIDR",