This is an automated email from the ASF dual-hosted git repository.
houston pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr-operator.git
The following commit(s) were added to refs/heads/main by this push:
new 66d6d89 More e2e test improvements
66d6d89 is described below
commit 66d6d89502f6d748f4e74f2dfeb11c5ea4f156b3
Author: Houston Putman <[email protected]>
AuthorDate: Mon May 15 10:55:51 2023 -0400
More e2e test improvements
- Failure information is now provided per-failure.
Currently test namespace is printed.
- Solr-Ready logic has been factored out and improved to fix
race-condition with StatefulSets being deleted and recreated.
---
tests/e2e/backups_test.go | 4 +---
tests/e2e/prometheus_exporter_test.go | 4 +---
tests/e2e/resource_utils_test.go | 15 ++++++++++++++-
tests/e2e/solrcloud_basic_test.go | 4 +---
tests/e2e/solrcloud_rolling_upgrade_test.go | 4 +---
tests/e2e/suite_test.go | 23 +++++++++++++++++++++++
6 files changed, 41 insertions(+), 13 deletions(-)
diff --git a/tests/e2e/backups_test.go b/tests/e2e/backups_test.go
index 1057522..7c3c7e1 100644
--- a/tests/e2e/backups_test.go
+++ b/tests/e2e/backups_test.go
@@ -67,9 +67,7 @@ var _ = FDescribe("E2E - Backups", Ordered, func() {
})
By("Waiting for the SolrCloud to come up healthy")
- solrCloud = expectSolrCloudWithChecks(ctx, solrCloud, func(g
Gomega, found *solrv1beta1.SolrCloud) {
-
g.Expect(found.Status.ReadyReplicas).To(Equal(*found.Spec.Replicas), "The
SolrCloud should have all nodes come up healthy")
- })
+ solrCloud = expectSolrCloudToBeReady(ctx, solrCloud)
By("creating a Solr Collection to backup")
createAndQueryCollection(ctx, solrCloud, solrCollection, 1, 2)
diff --git a/tests/e2e/prometheus_exporter_test.go
b/tests/e2e/prometheus_exporter_test.go
index 23ac6a4..003d1ea 100644
--- a/tests/e2e/prometheus_exporter_test.go
+++ b/tests/e2e/prometheus_exporter_test.go
@@ -53,9 +53,7 @@ var _ = FDescribe("E2E - Prometheus Exporter", Ordered,
func() {
})
By("waiting for the SolrCloud to come up healthy")
- solrCloud = expectSolrCloudWithChecks(ctx, solrCloud, func(g
Gomega, found *solrv1beta1.SolrCloud) {
-
g.Expect(found.Status.ReadyReplicas).To(Equal(*found.Spec.Replicas), "The
SolrCloud should have all nodes come up healthy")
- })
+ solrCloud = expectSolrCloudToBeReady(ctx, solrCloud)
By("creating a Solr Collection to query metrics for")
createAndQueryCollection(ctx, solrCloud, solrCollection, 1, 2)
diff --git a/tests/e2e/resource_utils_test.go b/tests/e2e/resource_utils_test.go
index 3a9853f..3c6c9fb 100644
--- a/tests/e2e/resource_utils_test.go
+++ b/tests/e2e/resource_utils_test.go
@@ -58,13 +58,26 @@ func deleteAndWait(ctx context.Context, object
client.Object, additionalOffset .
Expect(err).ToNot(HaveOccurred(), "Error fetching objectKind")
Expect(kinds).ToNot(BeEmpty(), "No objectKinds found for object")
objKind := kinds[0]
- Expect(k8sClient.Delete(ctx, object)).To(Or(Succeed(),
MatchError(HaveSuffix("%q not found", testNamespace()))), "Failed to delete %s
%s after test", objKind.Kind, key.Name)
+ Expect(k8sClient.Delete(ctx, object)).To(Or(Succeed(),
MatchError(HaveSuffix("%q not found", object.GetName()))), "Failed to delete %s
%s after test", objKind.Kind, key.Name)
EventuallyWithOffset(resolveOffset(additionalOffset), func() error {
return k8sClient.Get(ctx, key, object)
}).Within(time.Minute).
Should(MatchError(HaveSuffix("%q not found", key.Name)),
objKind.Kind+" exists when it should not")
}
+func expectSolrCloudToBeReady(ctx context.Context, solrCloud
*solrv1beta1.SolrCloud, additionalOffset ...int) *solrv1beta1.SolrCloud {
+ return expectSolrCloudWithChecks(ctx, solrCloud, func(g Gomega, found
*solrv1beta1.SolrCloud) {
+
g.Expect(found.Status.ReadyReplicas).To(Equal(*found.Spec.Replicas), "The
SolrCloud should have all nodes come up healthy")
+ // We have to check the status.replicas, because when a cloud
is deleted/recreated, the statefulset can be recreated
+ // before the pods of the previous statefulset are deleted. So
those pods will still be matched to the label selector,
+ // but the new statefulset doesn't know about them.
+ // The "Status.ReadyReplicas" value is populated from querying
with the label selector
+ // The "Status.Replicas" value is populated from the
statefulSet status
+ // So we need both to be equal to the requested number of
replicas in order to know the statefulset is ready to go.
+ g.Expect(found.Status.Replicas).To(Equal(*found.Spec.Replicas),
"The SolrCloud should have all nodes come up healthy")
+ }, resolveOffset(additionalOffset))
+}
+
func expectSolrCloud(ctx context.Context, solrCloud *solrv1beta1.SolrCloud,
additionalOffset ...int) *solrv1beta1.SolrCloud {
return expectSolrCloudWithChecks(ctx, solrCloud, nil,
resolveOffset(additionalOffset))
}
diff --git a/tests/e2e/solrcloud_basic_test.go
b/tests/e2e/solrcloud_basic_test.go
index c600d72..be3961a 100644
--- a/tests/e2e/solrcloud_basic_test.go
+++ b/tests/e2e/solrcloud_basic_test.go
@@ -43,9 +43,7 @@ var _ = FDescribe("E2E - SolrCloud - Basic", func() {
})
By("Waiting for the SolrCloud to come up healthy")
- solrCloud = expectSolrCloudWithChecks(ctx, solrCloud, func(g
Gomega, found *solrv1beta1.SolrCloud) {
-
g.Expect(found.Status.ReadyReplicas).To(Equal(*found.Spec.Replicas), "The
SolrCloud should have all nodes come up healthy")
- })
+ solrCloud = expectSolrCloudToBeReady(ctx, solrCloud)
By("creating a first Solr Collection")
createAndQueryCollection(ctx, solrCloud, "basic", 1, 1)
diff --git a/tests/e2e/solrcloud_rolling_upgrade_test.go
b/tests/e2e/solrcloud_rolling_upgrade_test.go
index 81b730c..567e359 100644
--- a/tests/e2e/solrcloud_rolling_upgrade_test.go
+++ b/tests/e2e/solrcloud_rolling_upgrade_test.go
@@ -48,9 +48,7 @@ var _ = FDescribe("E2E - SolrCloud - Rolling Upgrades",
func() {
})
By("Waiting for the SolrCloud to come up healthy")
- solrCloud = expectSolrCloudWithChecks(ctx, solrCloud, func(g
Gomega, found *solrv1beta1.SolrCloud) {
-
g.Expect(found.Status.ReadyReplicas).To(Equal(*found.Spec.Replicas), "The
SolrCloud should have all nodes come up healthy")
- })
+ solrCloud = expectSolrCloudToBeReady(ctx, solrCloud)
By("creating a first Solr Collection")
createAndQueryCollection(ctx, solrCloud, solrCollection1, 1, 2)
diff --git a/tests/e2e/suite_test.go b/tests/e2e/suite_test.go
index c53026c..770965b 100644
--- a/tests/e2e/suite_test.go
+++ b/tests/e2e/suite_test.go
@@ -159,9 +159,32 @@ func (rc RetryCommand) String() string {
)
}
+type FailureInformation struct {
+ namespace string
+}
+
+// ColorableString for ReportEntry to use
+func (fi FailureInformation) ColorableString() string {
+ return fmt.Sprintf("{{yellow}}%s{{/}}", fi)
+}
+
+// non-colorable String() is used by go's string formatting support but
ignored by ReportEntry
+func (fi FailureInformation) String() string {
+ return fmt.Sprintf(
+ "Namespace: %s\n",
+ fi.namespace,
+ )
+}
+
var _ = ReportAfterEach(func(report SpecReport) {
if report.Failed() {
ginkgoConfig, _ := GinkgoConfiguration()
+ AddReportEntry(
+ "Failure Information",
+ FailureInformation{
+ namespace: testNamespace(),
+ },
+ )
AddReportEntry(
"Re-Run Failed Test Using Command",
types.CodeLocation{},