Skip to content

Commit

Permalink
test(e2e): use MeshService mode and generated hostname (#11832)
Browse files Browse the repository at this point in the history
I've noticed a flake of the test

I switched to using MeshService mode instead of manually creating a
MeshService. I'm not sure if MeshService might be removed since the Mesh
has `meshServices.mode` disabled. Additionally, I changed the hostname
to use generated one.

<!-- Is there a MADR? An Issue? A related PR? -->

Fix #XX

<!--
> Changelog: skip
-->
<!--
Uncomment the above section to explicitly set a [`> Changelog:` entry
here](https://github.com/kumahq/kuma/blob/master/CONTRIBUTING.md#submitting-a-patch)?
-->

---------

Signed-off-by: Lukasz Dziedziak <[email protected]>
  • Loading branch information
lukidzi authored and kumahq[bot] committed Oct 23, 2024
1 parent 6420c84 commit 0ed96b8
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions test/e2e_env/universal/meshhealthcheck/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
"github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
"github.com/kumahq/kuma/pkg/test/resources/samples"
. "github.com/kumahq/kuma/test/framework"
"github.com/kumahq/kuma/test/framework/client"
"github.com/kumahq/kuma/test/framework/envs/universal"
Expand Down Expand Up @@ -55,6 +57,12 @@ spec:
Expect(err).ToNot(HaveOccurred())
})

<<<<<<< HEAD

Check failure on line 60 in test/e2e_env/universal/meshhealthcheck/policy.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected <<, expected }
=======
AfterEachFailure(func() {

Check failure on line 62 in test/e2e_env/universal/meshhealthcheck/policy.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected { at end of statement
DebugUniversal(universal.Cluster, meshName)
})

Check failure on line 64 in test/e2e_env/universal/meshhealthcheck/policy.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected ) after top level declaration

E2EAfterAll(func() {

Check failure on line 66 in test/e2e_env/universal/meshhealthcheck/policy.go

View workflow job for this annotation

GitHub Actions / lint

method has no receiver

Check failure on line 66 in test/e2e_env/universal/meshhealthcheck/policy.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected {, expected name
Expect(universal.Cluster.DeleteMeshApps(meshName)).To(Succeed())
Expect(universal.Cluster.DeleteMesh(meshName)).To(Succeed())
Expand Down Expand Up @@ -92,6 +100,90 @@ spec:
})

Check failure on line 100 in test/e2e_env/universal/meshhealthcheck/policy.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected ) after top level declaration
}, Ordered)

Describe("HTTP to real MeshService", func() {
meshName := "meshhealthcheck-http-ms"
healthCheck := func(mesh, method, status string) string {
return fmt.Sprintf(`
type: MeshHealthCheck
mesh: %s
name: everything-to-backend
spec:
to:
- targetRef:
kind: MeshService
name: test-server
default:
interval: 10s
timeout: 2s
unhealthyThreshold: 3
healthyThreshold: 1
failTrafficOnPanic: true
noTrafficInterval: 1s
healthyPanicThreshold: 0
reuseConnection: true
http:
path: /%s
expectedStatuses:
- %s`, mesh, method, status)
}

BeforeAll(func() {
err := NewClusterSetup().
Install(Yaml(samples.MeshDefaultBuilder().
WithName(meshName).
WithMeshServicesEnabled(mesh_proto.Mesh_MeshServices_Exclusive),
)).
Install(YamlUniversal(healthCheck(meshName, "health", "200"))).
Install(DemoClientUniversal("dp-demo-client", meshName,
WithTransparentProxy(true)),
).
Install(TestServerUniversal("test-server", meshName, WithArgs([]string{"health-check", "http"}), WithProtocol(mesh.ProtocolHTTP))).
Setup(universal.Cluster)
Expect(err).ToNot(HaveOccurred())
})

AfterEachFailure(func() {
DebugUniversal(universal.Cluster, meshName)
})

>>>>>>> 07ac2c772 (test(e2e): use MeshService mode and generated hostname (#11832))
E2EAfterAll(func() {
Expect(universal.Cluster.DeleteMeshApps(meshName)).To(Succeed())
Expect(universal.Cluster.DeleteMesh(meshName)).To(Succeed())
})

It("should mark host as unhealthy if it doesn't reply on health checks", func() {
// check that test-server is healthy
Eventually(func(g Gomega) {
stdout, _, err := client.CollectResponse(
universal.Cluster, "dp-demo-client", "test-server.svc.mesh.local/content",
)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(stdout).To(ContainSubstring("response"))
}).Should(Succeed())

// update HealthCheck policy to check for another status code
Expect(YamlUniversal(healthCheck(meshName, "are-you-healthy", "500"))(universal.Cluster)).To(Succeed())

// wait cluster 'test-server' to be marked as unhealthy
Eventually(func(g Gomega) {
cmd := []string{"/bin/bash", "-c", "\"curl localhost:9901/clusters | grep test-server\""}
stdout, _, err := universal.Cluster.Exec("", "", "dp-demo-client", cmd...)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(stdout).To(ContainSubstring("health_flags::/failed_active_hc"))
}, "30s", "500ms").Should(Succeed())

// check that test-server is unhealthy
Consistently(func(g Gomega) {
response, err := client.CollectFailure(
universal.Cluster, "dp-demo-client", "test-server.svc.mesh.local/content",
)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(response.ResponseCode).To(Equal(503))
}).Should(Succeed())
})
}, Ordered)

Describe("TCP", func() {
healthCheck := func(mesh, serviceName, send, recv string) string {
sendBase64 := base64.StdEncoding.EncodeToString([]byte(send))
Expand Down

0 comments on commit 0ed96b8

Please sign in to comment.