You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gf...@apache.org on 2024/05/22 07:10:48 UTC

(camel-k) 02/02: fix(e2e): Fix flakiness in route tests

This is an automated email from the ASF dual-hosted git repository.

gfournier pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit a72f5b50aafe2ae5a4517469baac56ff0262dd0e
Author: Gaelle Fournier <ga...@gmail.com>
AuthorDate: Tue May 21 19:17:04 2024 +0200

    fix(e2e): Fix flakiness in route tests
---
 e2e/common/traits/route_test.go | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/e2e/common/traits/route_test.go b/e2e/common/traits/route_test.go
index 61149557d..a78d10286 100644
--- a/e2e/common/traits/route_test.go
+++ b/e2e/common/traits/route_test.go
@@ -105,14 +105,15 @@ func TestRunRoutes(t *testing.T) {
 		t.Run("Route unsecure http works", func(t *testing.T) {
 			g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/PlatformHttpServer.java").Execute()).To(Succeed())
 			g.Eventually(IntegrationPodPhase(t, ctx, ns, integrationName), TestTimeoutLong).Should(Equal(corev1.PodRunning))
-			route := Route(t, ctx, ns, integrationName)
-			g.Eventually(route, TestTimeoutMedium).ShouldNot(BeNil())
+			g.Eventually(Route(t, ctx, ns, integrationName), TestTimeoutMedium).ShouldNot(BeNil())
 			// must wait a little time after route is created, before doing an http request,
 			// otherwise the route is unavailable and the http request will fail
 			time.Sleep(waitBeforeHttpRequest)
+			route := Route(t, ctx, ns, integrationName)
 			url := fmt.Sprintf("http://%s/hello?name=Simple", route().Spec.Host)
 			g.Eventually(httpRequest(url, false), TestTimeoutShort).Should(Equal("Hello Simple"))
 			g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).Should(BeNil())
+			g.Eventually(Route(t, ctx, ns, integrationName), TestTimeoutMedium).Should(BeNil())
 		})
 
 		// =============================
@@ -121,14 +122,15 @@ func TestRunRoutes(t *testing.T) {
 		t.Run("Route Edge https works", func(t *testing.T) {
 			g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/PlatformHttpServer.java", "-t", "route.tls-termination=edge").Execute()).To(Succeed())
 			g.Eventually(IntegrationPodPhase(t, ctx, ns, integrationName), TestTimeoutLong).Should(Equal(corev1.PodRunning))
-			route := Route(t, ctx, ns, integrationName)
-			g.Eventually(route, TestTimeoutMedium).ShouldNot(BeNil())
+			g.Eventually(Route(t, ctx, ns, integrationName), TestTimeoutMedium).ShouldNot(BeNil())
 			// must wait a little time after route is created, before an http request,
 			// otherwise the route is unavailable and the http request will fail
 			time.Sleep(waitBeforeHttpRequest)
+			route := Route(t, ctx, ns, integrationName)
 			url := fmt.Sprintf("https://%s/hello?name=TLS_Edge", route().Spec.Host)
 			g.Eventually(httpRequest(url, true), TestTimeoutShort).Should(Equal("Hello TLS_Edge"))
 			g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).Should(BeNil())
+			g.Eventually(Route(t, ctx, ns, integrationName), TestTimeoutMedium).Should(BeNil())
 		})
 
 		// =============================
@@ -137,15 +139,16 @@ func TestRunRoutes(t *testing.T) {
 		t.Run("Route Edge (custom certificate) https works", func(t *testing.T) {
 			g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/PlatformHttpServer.java", "-t", "route.tls-termination=edge", "-t", "route.tls-certificate-secret="+refCert, "-t", "route.tls-key-secret="+refKey).Execute()).To(Succeed())
 			g.Eventually(IntegrationPodPhase(t, ctx, ns, integrationName), TestTimeoutLong).Should(Equal(corev1.PodRunning))
-			route := Route(t, ctx, ns, integrationName)
-			g.Eventually(route, TestTimeoutMedium).ShouldNot(BeNil())
+			g.Eventually(Route(t, ctx, ns, integrationName), TestTimeoutMedium).ShouldNot(BeNil())
 			// must wait a little time after route is created, before an http request,
 			// otherwise the route is unavailable and the http request will fail
 			time.Sleep(waitBeforeHttpRequest)
+			route := Route(t, ctx, ns, integrationName)
 			code := "TLS_EdgeCustomCertificate"
 			url := fmt.Sprintf("https://%s/hello?name=%s", route().Spec.Host, code)
 			g.Eventually(httpRequest(url, true), TestTimeoutShort).Should(Equal("Hello " + code))
 			g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).Should(BeNil())
+			g.Eventually(Route(t, ctx, ns, integrationName), TestTimeoutMedium).Should(BeNil())
 		})
 
 		// =============================
@@ -154,15 +157,16 @@ func TestRunRoutes(t *testing.T) {
 		t.Run("Route passthrough https works", func(t *testing.T) {
 			g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/PlatformHttpServer.java", "--resource", "secret:"+secretName+"@/etc/ssl/"+secretName, "-p", "quarkus.http.ssl.certificate.files=/etc/ssl/"+secretName+"/tls.crt", "-p", "quarkus.http.ssl.certificate.key-files=/etc/ssl/"+secretName+"/tls.key", "-t", "route.tls-termination=passthrough", "-t", "container.port=8443").Execute()).To(Succeed())
 			g.Eventually(IntegrationPodPhase(t, ctx, ns, integrationName), TestTimeoutLong).Should(Equal(corev1.PodRunning))
-			route := Route(t, ctx, ns, integrationName)
-			g.Eventually(route, TestTimeoutMedium).ShouldNot(BeNil())
+			g.Eventually(Route(t, ctx, ns, integrationName), TestTimeoutMedium).ShouldNot(BeNil())
 			// must wait a little time after route is created, before an http request,
 			// otherwise the route is unavailable and the http request will fail
 			time.Sleep(waitBeforeHttpRequest)
+			route := Route(t, ctx, ns, integrationName)
 			code := "TLS_Passthrough"
 			url := fmt.Sprintf("https://%s/hello?name=%s", route().Spec.Host, code)
 			g.Eventually(httpRequest(url, true), TestTimeoutShort).Should(Equal("Hello " + code))
 			g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).Should(BeNil())
+			g.Eventually(Route(t, ctx, ns, integrationName), TestTimeoutMedium).Should(BeNil())
 		})
 
 		// =============================
@@ -171,26 +175,27 @@ func TestRunRoutes(t *testing.T) {
 		t.Run("Route Reencrypt https works", func(t *testing.T) {
 			g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/PlatformHttpServer.java", "--resource", "secret:"+secretName+"@/etc/ssl/"+secretName, "-p", "quarkus.http.ssl.certificate.files=/etc/ssl/"+secretName+"/tls.crt", "-p", "quarkus.http.ssl.certificate.key-files=/etc/ssl/"+secretName+"/tls.key", "-t", "route.tls-termination=reencrypt", "-t", "route.tls-destination-ca-certificate-secret="+refCert, "-t", "route.tls-certificate-secret="+refCert, "-t", "route.tls-key-secret="+refKey, "-t" [...]
 			g.Eventually(IntegrationPodPhase(t, ctx, ns, integrationName), TestTimeoutLong).Should(Equal(corev1.PodRunning))
-
-			route := Route(t, ctx, ns, integrationName)
-			g.Eventually(route, TestTimeoutMedium).ShouldNot(BeNil())
+			g.Eventually(Route(t, ctx, ns, integrationName), TestTimeoutMedium).ShouldNot(BeNil())
 			// must wait a little time after route is created, before an http request,
 			// otherwise the route is unavailable and the http request will fail
+			route := Route(t, ctx, ns, integrationName)
 			time.Sleep(waitBeforeHttpRequest)
 			code := "TLS_Reencrypt"
 			url := fmt.Sprintf("https://%s/hello?name=%s", route().Spec.Host, code)
 			g.Eventually(httpRequest(url, true), TestTimeoutShort).Should(Equal("Hello " + code))
 			g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).Should(BeNil())
+			g.Eventually(Route(t, ctx, ns, integrationName), TestTimeoutMedium).Should(BeNil())
 		})
 
 		t.Run("Route annotations added", func(t *testing.T) {
+			g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).Should(BeNil())
 			g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/PlatformHttpServer.java", "-t", "route.annotations.'haproxy.router.openshift.io/balance'=roundrobin").Execute()).To(Succeed())
 			g.Eventually(IntegrationPodPhase(t, ctx, ns, integrationName), TestTimeoutLong).Should(Equal(corev1.PodRunning))
-			route := RouteFull(t, ctx, ns, integrationName)()
-			g.Eventually(route, TestTimeoutMedium).ShouldNot(BeNil())
+			g.Eventually(Route(t, ctx, ns, integrationName), TestTimeoutMedium).ShouldNot(BeNil())
 			// must wait a little time after route is created, before an http request,
 			// otherwise the route is unavailable and the http request will fail
 			time.Sleep(waitBeforeHttpRequest)
+			route := RouteFull(t, ctx, ns, integrationName)()
 			var annotations = route.ObjectMeta.Annotations
 			g.Expect(annotations["haproxy.router.openshift.io/balance"]).To(Equal("roundrobin"))
 
@@ -198,6 +203,7 @@ func TestRunRoutes(t *testing.T) {
 			g.Eventually(UnstructuredIntegration(t, ctx, ns, integrationName)).ShouldNot(BeNil())
 			unstructuredIntegration := UnstructuredIntegration(t, ctx, ns, integrationName)()
 			routeTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "route")
+			fmt.Printf("len(routeTrait): %d\n", len(routeTrait))
 			g.Expect(routeTrait).ToNot(BeNil())
 			g.Expect(len(routeTrait)).To(Equal(1))
 			g.Expect(routeTrait["annotations"]).ToNot(BeNil())