This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/camel-k.gitThe following commit(s) were added to refs/heads/master by this push:
new fa20696 chore(e2e): Assert Integration readiness condition in scaling e2e tests
fa20696 is described below
commit fa20696c0acdc8a37eea8d27c66c5fd4826681ce
Author: Antonin Stefanutti <
[hidden email]>
AuthorDate: Mon Feb 22 17:23:09 2021 +0100
chore(e2e): Assert Integration readiness condition in scaling e2e tests
---
e2e/common/scale_test.go | 48 +++++++++++++++++++++++--------------------
e2e/common/traits/pdb_test.go | 15 ++++----------
e2e/support/test_support.go | 7 ++++++-
3 files changed, 36 insertions(+), 34 deletions(-)
diff --git a/e2e/common/scale_test.go b/e2e/common/scale_test.go
index d0925dd..50634f2 100644
--- a/e2e/common/scale_test.go
+++ b/e2e/common/scale_test.go
@@ -49,6 +49,19 @@ func TestIntegrationScale(t *testing.T) {
Eventually(IntegrationCondition(ns, name, camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
+ t.Run("Update integration scale spec", func(t *testing.T) {
+ Expect(ScaleIntegration(ns, name, 3)).To(Succeed())
+ // Check the readiness condition becomes falsy
+ Eventually(IntegrationCondition(ns, name, camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionFalse))
+ // Check the scale cascades into the Deployment scale
+ Eventually(IntegrationPods(ns, name), TestTimeoutShort).Should(HaveLen(3))
+ // Check it also cascades into the Integration scale subresource Status field
+ Eventually(IntegrationStatusReplicas(ns, name), TestTimeoutShort).
+ Should(gstruct.PointTo(BeNumerically("==", 3)))
+ // Finally check the readiness condition becomes truthy back
+ Eventually(IntegrationCondition(ns, name, camelv1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(v1.ConditionTrue))
+ })
+
t.Run("Scale integration with polymorphic client", func(t *testing.T) {
// Polymorphic scale client
groupResources, err := restmapper.GetAPIGroupResources(TestClient().Discovery())
@@ -59,18 +72,20 @@ func TestIntegrationScale(t *testing.T) {
Expect(err).To(BeNil())
// Patch the integration scale subresource
- patch := "{\"spec\":{\"replicas\":3}}"
+ patch := "{\"spec\":{\"replicas\":2}}"
_, err = scaleClient.Scales(ns).Patch(TestContext, camelv1.SchemeGroupVersion.WithResource("integrations"), name, types.MergePatchType, []byte(patch), metav1.PatchOptions{})
Expect(err).To(BeNil())
+ // Check the readiness condition is still truthy as down-scaling
+ Expect(IntegrationCondition(ns, name, camelv1.IntegrationConditionReady)()).To(Equal(v1.ConditionTrue))
// Check the Integration scale subresource Spec field
Eventually(IntegrationSpecReplicas(ns, name), TestTimeoutShort).
- Should(gstruct.PointTo(BeNumerically("==", 3)))
+ Should(gstruct.PointTo(BeNumerically("==", 2)))
// Then check it cascades into the Deployment scale
- Eventually(IntegrationPods(ns, name), TestTimeoutMedium).Should(HaveLen(3))
+ Eventually(IntegrationPods(ns, name), TestTimeoutShort).Should(HaveLen(2))
// Finally check it cascades into the Integration scale subresource Status field
Eventually(IntegrationStatusReplicas(ns, name), TestTimeoutShort).
- Should(gstruct.PointTo(BeNumerically("==", 3)))
+ Should(gstruct.PointTo(BeNumerically("==", 2)))
})
t.Run("Scale integration with Camel K client", func(t *testing.T) {
@@ -80,32 +95,21 @@ func TestIntegrationScale(t *testing.T) {
// Getter
integrationScale, err := camel.CamelV1().Integrations(ns).GetScale(TestContext, name, metav1.GetOptions{})
Expect(err).To(BeNil())
- Expect(integrationScale.Spec.Replicas).To(BeNumerically("==", 3))
- Expect(integrationScale.Status.Replicas).To(BeNumerically("==", 3))
+ Expect(integrationScale.Spec.Replicas).To(BeNumerically("==", 2))
+ Expect(integrationScale.Status.Replicas).To(BeNumerically("==", 2))
// Setter
- integrationScale.Spec.Replicas = 2
+ integrationScale.Spec.Replicas = 1
integrationScale, err = camel.CamelV1().Integrations(ns).UpdateScale(TestContext, name, integrationScale, metav1.UpdateOptions{})
Expect(err).To(BeNil())
+ // Check the readiness condition is still truthy as down-scaling
+ Expect(IntegrationCondition(ns, name, camelv1.IntegrationConditionReady)()).To(Equal(v1.ConditionTrue))
// Check the Integration scale subresource Spec field
Eventually(IntegrationSpecReplicas(ns, name), TestTimeoutShort).
- Should(gstruct.PointTo(BeNumerically("==", 2)))
+ Should(gstruct.PointTo(BeNumerically("==", 1)))
// Then check it cascades into the Deployment scale
- Eventually(IntegrationPods(ns, name), TestTimeoutMedium).Should(HaveLen(2))
- // Finally check it cascades into the Integration scale subresource Status field
- Eventually(IntegrationStatusReplicas(ns, name), TestTimeoutShort).
- Should(gstruct.PointTo(BeNumerically("==", 2)))
- })
-
- t.Run("Update integration scale spec", func(t *testing.T) {
- Expect(UpdateIntegration(ns, name, func(it *camelv1.Integration) {
- replicas := int32(1)
- it.Spec.Replicas = &replicas
- })).To(Succeed())
-
- // Check it cascades into the Deployment scale
- Eventually(IntegrationPods(ns, name), TestTimeoutMedium).Should(HaveLen(1))
+ Eventually(IntegrationPods(ns, name), TestTimeoutShort).Should(HaveLen(1))
// Finally check it cascades into the Integration scale subresource Status field
Eventually(IntegrationStatusReplicas(ns, name), TestTimeoutShort).
Should(gstruct.PointTo(BeNumerically("==", 1)))
diff --git a/e2e/common/traits/pdb_test.go b/e2e/common/traits/pdb_test.go
index c72e7b9..376db27 100644
--- a/e2e/common/traits/pdb_test.go
+++ b/e2e/common/traits/pdb_test.go
@@ -74,10 +74,7 @@ func TestPodDisruptionBudget(t *testing.T) {
))
// Scale Integration
- Expect(UpdateIntegration(ns, name, func(it *camelv1.Integration) {
- replicas := int32(2)
- it.Spec.Replicas = &replicas
- })).To(Succeed())
+ Expect(ScaleIntegration(ns, name, 2)).To(Succeed())
Eventually(IntegrationPods(ns, name), TestTimeoutMedium).Should(HaveLen(2))
Eventually(IntegrationStatusReplicas(ns, name), TestTimeoutShort).
Should(gstruct.PointTo(BeNumerically("==", 2)))
@@ -127,10 +124,7 @@ func TestPodDisruptionBudget(t *testing.T) {
// Scale Integration to Scale > PodDisruptionBudgetSpec.MinAvailable
// for the eviction request to succeed once replicas are ready
- Expect(UpdateIntegration(ns, name, func(it *camelv1.Integration) {
- replicas := int32(3)
- it.Spec.Replicas = &replicas
- })).To(Succeed())
+ Expect(ScaleIntegration(ns, name, 3)).To(Succeed())
Eventually(IntegrationPods(ns, name), TestTimeoutMedium).Should(HaveLen(3))
Eventually(IntegrationStatusReplicas(ns, name), TestTimeoutShort).
Should(gstruct.PointTo(BeNumerically("==", 3)))
@@ -138,12 +132,11 @@ func TestPodDisruptionBudget(t *testing.T) {
pods = IntegrationPods(ns, name)()
Expect(pods).To(HaveLen(3))
- err = TestClient().CoreV1().Pods(ns).Evict(TestContext, &policy.Eviction{
+ Expect(TestClient().CoreV1().Pods(ns).Evict(TestContext, &policy.Eviction{
ObjectMeta: metav1.ObjectMeta{
Name: pods[0].Name,
},
- })
- Expect(err).To(Succeed())
+ })).To(Succeed())
// Clean up
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index fd57f32..f4d8022 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -483,6 +483,12 @@ func UpdateIntegration(ns string, name string, upd func(it *v1.Integration)) err
return TestClient().Update(TestContext, it)
}
+func ScaleIntegration(ns string, name string, replicas int32) error {
+ return UpdateIntegration(ns, name, func(it *v1.Integration) {
+ it.Spec.Replicas = &replicas
+ })
+}
+
func Kits(ns string) func() []v1.IntegrationKit {
return func() []v1.IntegrationKit {
lst := v1.NewIntegrationKitList()
@@ -1089,7 +1095,6 @@ func UserCleanup() {
func InvokeUserTestCode(t *testing.T, ns string, doRun func(string)) {
defer func() {
if t.Failed() {
-
if err := util.Dump(TestContext, TestClient(), ns, t); err != nil {
t.Logf("Error while dumping namespace %s: %v\n", ns, err)
}