From d59107770cae4175a5772bb6b806ad95b54b72f2 Mon Sep 17 00:00:00 2001 From: Deepthi Devaki Akkoorath Date: Thu, 8 Dec 2022 16:48:16 +0100 Subject: [PATCH 1/2] test: remove unused helper method --- go-chaos/internal/helper_test.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/go-chaos/internal/helper_test.go b/go-chaos/internal/helper_test.go index 51d392aea..33c6bc844 100644 --- a/go-chaos/internal/helper_test.go +++ b/go-chaos/internal/helper_test.go @@ -79,15 +79,6 @@ func (c K8Client) CreatePodWithLabelsAndName(t *testing.T, selector *metav1.Labe require.NoError(t, err) } -func (c K8Client) CreateReadyPodWithLabelsAndName(t *testing.T, selector *metav1.LabelSelector, podName string) { - _, err := c.Clientset.CoreV1().Pods(c.GetCurrentNamespace()).Create(context.TODO(), &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{Labels: selector.MatchLabels, Name: podName}, - Spec: v1.PodSpec{}, - }, metav1.CreateOptions{}) - - require.NoError(t, err) -} - func (c K8Client) CreateBrokerPodsWithStatus(t *testing.T, selector *metav1.LabelSelector, podName string, podPhase v1.PodPhase, readyStatus bool) { _, err := c.Clientset.CoreV1().Pods(c.GetCurrentNamespace()).Create(context.TODO(), &v1.Pod{ ObjectMeta: metav1.ObjectMeta{Labels: selector.MatchLabels, Name: podName}, From 07cd4a66be3b895f2c7562f62fecfe7cf32e05ad Mon Sep 17 00:00:00 2001 From: Deepthi Devaki Akkoorath Date: Thu, 8 Dec 2022 16:48:36 +0100 Subject: [PATCH 2/2] test: make tick time configurable to reduce test duration --- go-chaos/internal/pods.go | 6 +++--- go-chaos/internal/pods_test.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go-chaos/internal/pods.go b/go-chaos/internal/pods.go index a2eaf6901..b9cf658cd 100644 --- a/go-chaos/internal/pods.go +++ b/go-chaos/internal/pods.go @@ -121,12 +121,12 @@ func (c K8Client) RestartPodWithGracePeriod(podName string, gracePeriodSec *int6 } func (c K8Client) AwaitReadiness() error { - return c.AwaitReadinessWithTimeout(5 * time.Minute) + return c.AwaitReadinessWithTimeout(5*time.Minute, 1*time.Second) } -func (c K8Client) AwaitReadinessWithTimeout(timeout time.Duration) error { +func (c K8Client) AwaitReadinessWithTimeout(timeout time.Duration, tickTime time.Duration) error { timedOut := time.After(timeout) - ticker := time.Tick(1 * time.Second) + ticker := time.Tick(tickTime) // Keep checking until we're timed out for { diff --git a/go-chaos/internal/pods_test.go b/go-chaos/internal/pods_test.go index e6fd5d929..147c986d9 100644 --- a/go-chaos/internal/pods_test.go +++ b/go-chaos/internal/pods_test.go @@ -283,7 +283,7 @@ func Test_ShouldReturnTrueWhenBrokersAreReady(t *testing.T) { k8Client.CreateDeploymentWithLabelsAndName(t, gatewaySelector, "gateway") // when - err = k8Client.AwaitReadinessWithTimeout(2 * time.Second) + err = k8Client.AwaitReadinessWithTimeout(100*time.Millisecond, 1*time.Millisecond) // then require.NoError(t, err) @@ -304,7 +304,7 @@ func Test_ShouldReturnErrorWhenAtleastOneBrokerIsNotReady(t *testing.T) { k8Client.CreateDeploymentWithLabelsAndName(t, gatewaySelector, "gateway") // when - err = k8Client.AwaitReadinessWithTimeout(2 * time.Second) + err = k8Client.AwaitReadinessWithTimeout(100*time.Millisecond, 1*time.Second) // then require.Error(t, err) @@ -325,7 +325,7 @@ func Test_ShouldReturnErrorWhenAtleastOneBrokerIsNotRunning(t *testing.T) { k8Client.CreateDeploymentWithLabelsAndName(t, gatewaySelector, "gateway") // when - err = k8Client.AwaitReadinessWithTimeout(2 * time.Second) + err = k8Client.AwaitReadinessWithTimeout(100*time.Millisecond, 1*time.Second) // then require.Error(t, err)