Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
test/*: de-duplicate value timeout, retryInterval
Browse files Browse the repository at this point in the history
timeout and retryInterval were same for most of the components and was
duplicated.

closes: #502
Signed-off-by: knrt10 <kautilya@kinvolk.io>
  • Loading branch information
knrt10 committed Oct 7, 2020
1 parent c01551a commit 85fd4b8
Show file tree
Hide file tree
Showing 28 changed files with 51 additions and 91 deletions.
5 changes: 2 additions & 3 deletions test/calico/metadata_access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ spec:
`

retryInterval = 1 * time.Second
timeout = 5 * time.Minute
)

func TestNoMetadataAccessRandomPod(t *testing.T) { //nolint:funlen
Expand Down Expand Up @@ -99,7 +98,7 @@ func TestNoMetadataAccessRandomPod(t *testing.T) { //nolint:funlen
podsclient := client.Pods(ns.ObjectMeta.Name)

// Retry pod creation. This might fail if Linkerd is not ready yet and some requests might fail.
if err := wait.PollImmediate(retryInterval, timeout, func() (done bool, err error) {
if err := wait.PollImmediate(retryInterval, testutil.Timeout, func() (done bool, err error) {
p, err = podsclient.Create(context.TODO(), p, metav1.CreateOptions{})
if err != nil {
t.Logf("retrying pod creation, failed with: %v", err)
Expand All @@ -114,7 +113,7 @@ func TestNoMetadataAccessRandomPod(t *testing.T) { //nolint:funlen

phase := corev1.PodUnknown

if err := wait.PollImmediate(retryInterval, timeout, func() (done bool, err error) {
if err := wait.PollImmediate(retryInterval, testutil.Timeout, func() (done bool, err error) {
p, err := podsclient.Get(context.TODO(), p.ObjectMeta.Name, metav1.GetOptions{})
if err != nil {
return false, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package awsebscsidriver
import (
"fmt"
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -43,7 +42,7 @@ func TestCSIDriverDeployments(t *testing.T) {
test := test
t.Run(fmt.Sprintf("aws-ebs-csi-driver deployment:%s", test.deployment), func(t *testing.T) {
t.Parallel()
testutil.WaitForDeployment(t, client, namespace, test.deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, test.deployment, testutil.RetryInterval, testutil.Timeout)
})
}
}
3 changes: 1 addition & 2 deletions test/components/cert-manager/cert-manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package certmanager
import (
"fmt"
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -47,7 +46,7 @@ func TestCertManagerDeployments(t *testing.T) {
for _, test := range testCases {
t.Run(fmt.Sprintf("cert-manager deployment:%s", test.deployment), func(t *testing.T) {
t.Parallel()
testutil.WaitForDeployment(t, client, namespace, test.deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, test.deployment, testutil.RetryInterval, testutil.Timeout) //nolint:goscope
})
}
}
7 changes: 2 additions & 5 deletions test/components/cluster-autoscaler/cluster-autoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@ package clusterautoscaler

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)

const (
defaultDeploymentTimeout = 5 * time.Minute
defaultDeploymentProbeInterval = 5 * time.Second
name = "cluster-autoscaler-packet-cluster-autoscaler-chart"
name = "cluster-autoscaler-packet-cluster-autoscaler-chart"
)

func TestClusterAutoscalerDeployments(t *testing.T) {
Expand All @@ -36,6 +33,6 @@ func TestClusterAutoscalerDeployments(t *testing.T) {
t.Run("deployment", func(t *testing.T) {
t.Parallel()

testutil.WaitForDeployment(t, client, "kube-system", name, defaultDeploymentProbeInterval, defaultDeploymentTimeout)
testutil.WaitForDeployment(t, client, "kube-system", name, testutil.RetryInterval, testutil.Timeout)
})
}
5 changes: 2 additions & 3 deletions test/components/contour/contour_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package contour

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -31,7 +30,7 @@ func TestEnvoyDaemonset(t *testing.T) {

client := testutil.CreateKubeClient(t)

testutil.WaitForDaemonSet(t, client, namespace, daemonset, time.Second*5, time.Minute*5)
testutil.WaitForDaemonSet(t, client, namespace, daemonset, testutil.RetryInterval, testutil.Timeout)
}

func TestContourDeployment(t *testing.T) {
Expand All @@ -41,5 +40,5 @@ func TestContourDeployment(t *testing.T) {

client := testutil.CreateKubeClient(t)

testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
}
3 changes: 1 addition & 2 deletions test/components/coredns/coredns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package coredns

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -31,5 +30,5 @@ func TestCoreDNSDeployment(t *testing.T) {

client := testutil.CreateKubeClient(t)

testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
}
3 changes: 1 addition & 2 deletions test/components/dex/dex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package dex

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -33,6 +32,6 @@ func TestDexDeployment(t *testing.T) {
t.Parallel()
deployment := "dex"

testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
})
}
6 changes: 3 additions & 3 deletions test/components/external-dns/external-dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package externaldns

import (
"fmt"
testutil "github.com/kinvolk/lokomotive/test/components/util"
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)

const namespace = "external-dns"
Expand All @@ -32,6 +32,6 @@ func TestExternalDNSDeployments(t *testing.T) {
t.Run(fmt.Sprintf("deployment"), func(t *testing.T) {
t.Parallel()
deployment := "external-dns"
testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
})
}
5 changes: 2 additions & 3 deletions test/components/flatcar-linux-update-operator/fluo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package fluo

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -31,7 +30,7 @@ func TestUpdateAgentDaemonset(t *testing.T) {

client := testutil.CreateKubeClient(t)

testutil.WaitForDaemonSet(t, client, namespace, daemonset, time.Second*5, time.Minute*5)
testutil.WaitForDaemonSet(t, client, namespace, daemonset, testutil.RetryInterval, testutil.Timeout)
}

func TestUpdateOperatorDeployment(t *testing.T) {
Expand All @@ -41,5 +40,5 @@ func TestUpdateOperatorDeployment(t *testing.T) {

client := testutil.CreateKubeClient(t)

testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
}
3 changes: 1 addition & 2 deletions test/components/gangway/gangway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package gangway

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -33,6 +32,6 @@ func TestGangwayDeployment(t *testing.T) {
t.Parallel()
deployment := "gangway"

testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
})
}
8 changes: 1 addition & 7 deletions test/components/httpbin/httpbin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,16 @@ package httpbin
import (
"fmt"
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)

const (
defaultDeploymentTimeout = 5 * time.Minute
defaultDeploymentProbeInterval = 5 * time.Second
)

func TestHttpbinDeployments(t *testing.T) {
client := testutil.CreateKubeClient(t)

t.Run(fmt.Sprintf("deployment"), func(t *testing.T) {
t.Parallel()

testutil.WaitForDeployment(t, client, "httpbin", "httpbin", defaultDeploymentProbeInterval, defaultDeploymentTimeout)
testutil.WaitForDeployment(t, client, "httpbin", "httpbin", testutil.RetryInterval, testutil.Timeout)
})
}
8 changes: 1 addition & 7 deletions test/components/istio/istio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@ package istio_test

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)

const (
retryInterval = 3 * time.Second
timeout = 7 * time.Minute
)

func TestIstioDeployments(t *testing.T) {
deployments := []struct {
Namespace string
Expand All @@ -51,7 +45,7 @@ func TestIstioDeployments(t *testing.T) {
t.Run(d.Deployment, func(t *testing.T) {
t.Parallel()

testutil.WaitForDeployment(t, client, d.Namespace, d.Deployment, retryInterval, timeout)
testutil.WaitForDeployment(t, client, d.Namespace, d.Deployment, testutil.RetryInterval, testutil.TimeoutSlower)
})
}
}
2 changes: 1 addition & 1 deletion test/components/kubernetes/controller-manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ func TestControllerManagerDeployment(t *testing.T) {

client := testutil.CreateKubeClient(t)

testutil.WaitForDeployment(t, client, namespace, deployment, retryInterval, timeout)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
}
5 changes: 1 addition & 4 deletions test/components/kubernetes/kubelet_disruptive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package kubernetes
import (
"context"
"testing"
"time"

k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -49,10 +48,8 @@ func TestSelfHostedKubeletLabels(t *testing.T) {
t.Errorf("could not delete the node %s: %v", chosenNode, err)
}

retryInterval := time.Second * 5
timeout := time.Minute * 5
// Wait for the node to come up.
if err = wait.PollImmediate(retryInterval, timeout, func() (done bool, err error) {
if err = wait.PollImmediate(testutil.RetryInterval, testutil.Timeout, func() (done bool, err error) {
node, err := client.CoreV1().Nodes().Get(context.TODO(), chosenNode, metav1.GetOptions{})
if err != nil {
if k8serrors.IsNotFound(err) {
Expand Down
7 changes: 1 addition & 6 deletions test/components/kubernetes/kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@ package kubernetes

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)

const retryInterval = time.Second * 5

const timeout = time.Minute * 5

func TestSelfHostedKubeletPods(t *testing.T) {
t.Parallel()

Expand All @@ -36,5 +31,5 @@ func TestSelfHostedKubeletPods(t *testing.T) {
namespace := "kube-system"
daemonset := "kubelet"

testutil.WaitForDaemonSet(t, client, namespace, daemonset, retryInterval, timeout)
testutil.WaitForDaemonSet(t, client, namespace, daemonset, testutil.RetryInterval, testutil.Timeout)
}
10 changes: 3 additions & 7 deletions test/components/linkerd/linkerd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"fmt"
"io/ioutil"
"testing"
"time"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -58,7 +57,7 @@ func TestLinkerdDeployment(t *testing.T) {
t.Run(d, func(t *testing.T) {
t.Parallel()

testutil.WaitForDeployment(t, client, namespace, d, retryInterval, timeout)
testutil.WaitForDeployment(t, client, namespace, d, testutil.RetryInterval, testutil.TimeoutSlower)
})
}
}
Expand Down Expand Up @@ -116,9 +115,6 @@ spec:
- name: download-dir
emptyDir: {}
`

retryInterval = 5 * time.Second
timeout = 9 * time.Minute
)

//nolint: funlen
Expand Down Expand Up @@ -160,7 +156,7 @@ func TestLinkerdCheck(t *testing.T) {
podsClient := client.Pods(ns.Name)

// Retry pod creation. This might fail if Linkerd is not ready yet and some requests might fail.
if err := wait.PollImmediate(retryInterval, timeout, func() (done bool, err error) {
if err := wait.PollImmediate(testutil.RetryInterval, testutil.TimeoutSlower, func() (done bool, err error) {
pod, err = podsClient.Create(context.TODO(), pod, metav1.CreateOptions{})
if err != nil {
t.Logf("retrying pod creation, failed with: %v", err)
Expand All @@ -175,7 +171,7 @@ func TestLinkerdCheck(t *testing.T) {

phase := corev1.PodUnknown

if err := wait.PollImmediate(retryInterval, timeout, func() (done bool, err error) {
if err := wait.PollImmediate(testutil.RetryInterval, testutil.TimeoutSlower, func() (done bool, err error) {
p, err := podsClient.Get(context.TODO(), pod.Name, metav1.GetOptions{})
if err != nil {
return false, fmt.Errorf("couldn't get the pod %q: %w", pod.Name, err)
Expand Down
5 changes: 2 additions & 3 deletions test/components/metallb/metallb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package metallb

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -33,13 +32,13 @@ func TestMetalLBDeployment(t *testing.T) {
t.Parallel()
daemonset := "speaker"

testutil.WaitForDaemonSet(t, client, namespace, daemonset, time.Second*5, time.Minute*5)
testutil.WaitForDaemonSet(t, client, namespace, daemonset, testutil.RetryInterval, testutil.Timeout)
})

t.Run("controller deployment", func(t *testing.T) {
t.Parallel()
deployment := "controller"

testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
})
}
3 changes: 1 addition & 2 deletions test/components/metrics-server/metrics_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package metricsserver

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)
Expand All @@ -33,6 +32,6 @@ func TestMetricsServerDeployment(t *testing.T) {
t.Parallel()
deployment := "metrics-server"

testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
testutil.WaitForDeployment(t, client, namespace, deployment, testutil.RetryInterval, testutil.Timeout)
})
}
Loading

0 comments on commit 85fd4b8

Please sign in to comment.