Skip to content

Commit

Permalink
test(e2e): speedup universal tests
Browse files Browse the repository at this point in the history
Signed-off-by: Lukasz Dziedziak <[email protected]>
  • Loading branch information
lukidzi committed Jan 30, 2025
1 parent 9cc7487 commit 72c0c56
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 53 deletions.
36 changes: 20 additions & 16 deletions test/e2e_env/universal/meshretry/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,27 @@ func GrpcRetry() {

E2EAfterAll(func() {
Expect(universal.Cluster.DeleteMeshApps(meshName)).To(Succeed())
Expect(universal.Cluster.GetKumactlOptions().RunKumactl("delete", "dataplane", "fake-echo-server", "-m", meshName)).To(Succeed())
Expect(universal.Cluster.DeleteMesh(meshName)).To(Succeed())
})

It("should retry on GRPC connection failure", func() {
echoServerDataplane := fmt.Sprintf(`
type: Dataplane
faultInjection := fmt.Sprintf(`
type: MeshFaultInjection
mesh: "%s"
name: fake-echo-server
networking:
address: 241.0.0.1
inbound:
- port: 7777
servicePort: 7777
tags:
kuma.io/service: test-server
kuma.io/protocol: grpc
name: mesh-fault-injecton-500-grpc
spec:
targetRef:
kind: MeshService
name: test-server
from:
- targetRef:
kind: MeshService
name: test-client
default:
http:
- abort:
httpStatus: 500
percentage: "50.0"
`, meshName)
meshRetryPolicy := fmt.Sprintf(`
type: MeshRetry
Expand Down Expand Up @@ -100,8 +104,8 @@ spec:
g.Expect(grpcSuccessStats(g)).To(stats.BeGreaterThanZero())
}, "30s", "1s").Should(Succeed())

By("Adding a faulty dataplane")
Expect(universal.Cluster.Install(YamlUniversal(echoServerDataplane))).To(Succeed())
By("Adding a fault injection")
Expect(universal.Cluster.Install(YamlUniversal(faultInjection))).To(Succeed())

By("Clean counters")
Expect(admin.ResetCounters()).To(Succeed())
Expand All @@ -112,7 +116,7 @@ spec:
defer func() { lastFailureStats = failureStats.Stats[0] }()
g.Expect(failureStats).To(stats.BeGreaterThanZero())
g.Expect(failureStats).To(stats.BeGreaterThan(lastFailureStats))
}, "60s", "5s").MustPassRepeatedly(3).Should(Succeed())
}, "30s", "1s").MustPassRepeatedly(3).Should(Succeed())

By("Apply a MeshRetry policy")
Expect(universal.Cluster.Install(YamlUniversal(meshRetryPolicy))).To(Succeed())
Expand All @@ -127,6 +131,6 @@ spec:
defer func() { lastFailureStats = failureStats.Stats[0] }()
g.Expect(failureStats).To(Not(stats.BeGreaterThan(lastFailureStats)))
g.Expect(grpcSuccessStats(g)).To(stats.BeGreaterThanZero())
}, "30s", "5s").MustPassRepeatedly(3).Should(Succeed())
}, "30s", "1s").MustPassRepeatedly(3).Should(Succeed())
})
}
63 changes: 26 additions & 37 deletions test/e2e_env/universal/retry/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package retry

import (
"fmt"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -36,24 +35,25 @@ func Policy() {

E2EAfterAll(func() {
Expect(universal.Cluster.DeleteMeshApps(meshName)).To(Succeed())
Expect(universal.Cluster.GetKumactlOptions().RunKumactl("delete", "dataplane", "fake-echo-server", "-m", meshName)).To(Succeed())
Expect(universal.Cluster.DeleteMesh(meshName)).To(Succeed())
})

It("should retry on HTTP connection failure", func() {
echoServerDataplane := fmt.Sprintf(`
type: Dataplane
fiPolicy := fmt.Sprintf(`
type: FaultInjection
mesh: "%s"
name: fake-echo-server
networking:
address: 241.0.0.1
inbound:
- port: 7777
servicePort: 7777
tags:
kuma.io/service: test-server
kuma.io/protocol: http
`, meshName)
name: fi-retry
sources:
- match:
kuma.io/service: demo-client
destinations:
- match:
kuma.io/service: test-server
kuma.io/protocol: http
conf:
abort:
httpStatus: 500
percentage: 50`, meshName)
retryPolicy := fmt.Sprintf(`
type: Retry
mesh: "%s"
Expand All @@ -75,32 +75,22 @@ conf:
universal.Cluster, "demo-client", "test-server.mesh",
)
g.Expect(err).ToNot(HaveOccurred())
}).Should(Succeed())
Consistently(func(g Gomega) {
// -m 8 to wait for 8 seconds to beat the default 5s connect timeout
_, err := client.CollectEchoResponse(
universal.Cluster, "demo-client", "test-server.mesh",
client.WithMaxTime(8),
)
g.Expect(err).ToNot(HaveOccurred())
}).Should(Succeed())
}, "30s", "1s").MustPassRepeatedly(3).Should(Succeed())

By("Adding a faulty dataplane")
Expect(universal.Cluster.Install(YamlUniversal(echoServerDataplane))).To(Succeed())
By("Adding a fault injection")
Expect(universal.Cluster.Install(YamlUniversal(fiPolicy))).To(Succeed())

By("Check some errors happen")
var errs []error
for i := 0; i < 50; i++ {
time.Sleep(time.Millisecond * 100)
_, err := client.CollectEchoResponse(
Eventually(func(g Gomega) {
response, err := client.CollectFailure(
universal.Cluster, "demo-client", "test-server.mesh",
client.WithMaxTime(8),
client.NoFail(),
client.OutputFormat(`{ "received": { "status": %{response_code} } }`),
)
if err != nil {
errs = append(errs, err)
}
}
Expect(errs).ToNot(BeEmpty())

g.Expect(err).ToNot(HaveOccurred())
g.Expect(response.ResponseCode).To(Equal(500))
}, "30s", "100ms").Should(Succeed())

By("Apply a retry policy")
Expect(universal.Cluster.Install(YamlUniversal(retryPolicy))).To(Succeed())
Expand All @@ -109,9 +99,8 @@ conf:
Eventually(func(g Gomega) {
_, err := client.CollectEchoResponse(
universal.Cluster, "demo-client", "test-server.mesh",
client.WithMaxTime(8),
)
g.Expect(err).ToNot(HaveOccurred())
}, "1m", "1s", MustPassRepeatedly(3)).Should(Succeed())
}, "30s", "1s").MustPassRepeatedly(3).Should(Succeed())
})
}

0 comments on commit 72c0c56

Please sign in to comment.