Skip to content

Commit

Permalink
chore(e2e): Assert Integration readiness condition in scaling e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
astefanutti committed Feb 23, 2021
1 parent 4f74d67 commit fa20696
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 34 deletions.
48 changes: 26 additions & 22 deletions e2e/common/scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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) {
Expand All @@ -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)))
Expand Down
15 changes: 4 additions & 11 deletions e2e/common/traits/pdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -127,23 +124,19 @@ 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)))
Eventually(IntegrationCondition(ns, name, camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))

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())
Expand Down
7 changes: 6 additions & 1 deletion e2e/support/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit fa20696

Please sign in to comment.