Skip to content

Commit

Permalink
fix(e2e): Fix flakiness in route tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gansheer committed May 22, 2024
1 parent f093378 commit ab630d5
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions e2e/common/traits/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})

// =============================
Expand All @@ -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())
})

// =============================
Expand All @@ -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())
})

// =============================
Expand All @@ -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())
})

// =============================
Expand All @@ -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", "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
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"))

Expand Down

0 comments on commit ab630d5

Please sign in to comment.