Skip to content

Commit

Permalink
test: thanos querier e2e test - wait for deployment to be ready (#445)
Browse files Browse the repository at this point in the history
Adding assertion for Deployment to be ready to make Thanos querier
test more stable
  • Loading branch information
tremes authored Mar 27, 2024
1 parent dff984b commit deb9e5b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/e2e/framework/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,27 @@ func (f *Framework) AssertStatefulsetReady(name, namespace string, fns ...Option
}
}

// AssertDeploymentReady asserts that a deployment has the desired number of pods running
func (f *Framework) AssertDeploymentReady(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)
return err == nil && deployment.Status.ReadyReplicas == *deployment.Spec.Replicas, 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,
Expand Down
1 change: 1 addition & 0 deletions test/e2e/thanos_querier_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func singleStackWithSidecar(t *testing.T) {
thanosService := corev1.Service{}
f.GetResourceWithRetry(t, name, tq.Namespace, &thanosService)

f.AssertDeploymentReady(name, tq.Namespace, framework.WithTimeout(5*time.Minute))(t)
// Assert prometheus instance can be queried
stopChan := make(chan struct{})
defer close(stopChan)
Expand Down

0 comments on commit deb9e5b

Please sign in to comment.