From 5a3a41c09709608aaac65bfde05f26663d2abaf8 Mon Sep 17 00:00:00 2001 From: Jaromir Wysoglad Date: Wed, 23 Oct 2024 10:10:51 +0200 Subject: [PATCH] test: fix thanos TLS test --- test/e2e/framework/assertions.go | 27 ++++++++++++++++++++++ test/e2e/thanos_querier_controller_test.go | 3 ++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/test/e2e/framework/assertions.go b/test/e2e/framework/assertions.go index 064953e2..0d04c0c1 100644 --- a/test/e2e/framework/assertions.go +++ b/test/e2e/framework/assertions.go @@ -172,6 +172,33 @@ func (f *Framework) AssertDeploymentReady(name, namespace string, fns ...OptionF } } +// AssertDeploymentReadyAndStable asserts that a deployment has the desired number of pods running for 2 consecutive polls 5 seconds appart +func (f *Framework) AssertDeploymentReadyAndStable(name, namespace string, fns ...OptionFn) func(t *testing.T) { + option := AssertOption{ + PollInterval: 5 * time.Second, + WaitTimeout: DefaultTestTimeout, + } + for _, fn := range fns { + fn(&option) + } + return func(t *testing.T) { + key := types.NamespacedName{Name: name, Namespace: namespace} + if err := wait.PollUntilContextTimeout(context.Background(), option.PollInterval, option.WaitTimeout, true, func(ctx context.Context) (bool, error) { + deployment := &appsv1.Deployment{} + err := f.K8sClient.Get(context.Background(), key, deployment) + if err == nil && deployment.Status.ReadyReplicas == *deployment.Spec.Replicas { + time.Sleep(5 * time.Second) + err := f.K8sClient.Get(context.Background(), key, deployment) + return err == nil && deployment.Status.ReadyReplicas == *deployment.Spec.Replicas, nil + } else { + return false, nil + } + }); err != nil { + t.Fatal(err) + } + } +} + func (f *Framework) GetResourceWithRetry(t *testing.T, name, namespace string, obj client.Object) { option := AssertOption{ PollInterval: 5 * time.Second, diff --git a/test/e2e/thanos_querier_controller_test.go b/test/e2e/thanos_querier_controller_test.go index b5a5c350..b590eb14 100644 --- a/test/e2e/thanos_querier_controller_test.go +++ b/test/e2e/thanos_querier_controller_test.go @@ -179,7 +179,8 @@ func singleStackWithSidecarTLS(t *testing.T) { thanosService := corev1.Service{} f.GetResourceWithRetry(t, querierName, tq.Namespace, &thanosService) - f.AssertDeploymentReady(querierName, tq.Namespace, framework.WithTimeout(5*time.Minute))(t) + f.AssertDeploymentReadyAndStable(querierName, tq.Namespace, framework.WithTimeout(5*time.Minute))(t) + // Assert prometheus instance can be queried stopChan := make(chan struct{}) defer close(stopChan)