Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iosnapshot/history: fix test flake #9630

Merged
merged 5 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog/v1.18.0-beta1/snapshot-test-flake.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
changelog:
- type: NON_USER_FACING
description: >-
Resolve the iosnapshot/history_test flake, by ensuring that asynchronous operations
are provided time to complete.

skipCI-kube-tests:true
skipCI-docs-build:true
52 changes: 48 additions & 4 deletions projects/gloo/pkg/servers/iosnapshot/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ var _ = Describe("History", func() {
Status: apiv1.HTTPRouteStatus{},
},
}
history.SetKubeGatewayClient(clientBuilder.WithObjects(clientObjects...).Build())
setClientOnHistory(ctx, history, clientBuilder.WithObjects(clientObjects...))

inputSnapshotBytes, err := history.GetInputSnapshot(ctx)
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -181,7 +181,7 @@ var _ = Describe("History", func() {
Status: apiv1.GatewayStatus{},
},
}
history.SetKubeGatewayClient(clientBuilder.WithObjects(clientObjects...).Build())
setClientOnHistory(ctx, history, clientBuilder.WithObjects(clientObjects...))

inputSnapshotBytes, err := history.GetInputSnapshot(ctx)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -199,8 +199,11 @@ var _ = Describe("History", func() {
var gatewayList apiv1.GatewayList
err = json.Unmarshal(gatewayBytes, &gatewayList)
Expect(err).NotTo(HaveOccurred())
Expect(gatewayList.Items).To(HaveLen(1))
Expect(gatewayList.Items[0].GetName()).To(Equal("kubernetes-gateway"))

Expect(gatewayList.Items).To(ContainElement(
WithTransform(func(gateway apiv1.Gateway) string {
return gateway.GetName()
}, Equal("kubernetes-gateway"))))
})

})
Expand Down Expand Up @@ -257,3 +260,44 @@ func setSnapshotOnHistory(ctx context.Context, history History, snap *v1snap.Api
WithTimeout(time.Second*5).
Should(Succeed(), "setting snapshot is asynchronous, so block until snapshot is processed")
}

// setClientOnHistory sets the Kubernetes Client on the history, and blocks until it has been processed
// This is a utility method to help developers write tests, without having to worry about the asynchronous
// nature of the `Set` API on the History
func setClientOnHistory(ctx context.Context, history History, builder *fake.ClientBuilder) {
gwSignalObject := &apiv1.Gateway{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: "gw-signal",
Namespace: defaults.GlooSystem,
},
}

history.SetKubeGatewayClient(builder.WithObjects(gwSignalObject).Build())

Eventually(func(g Gomega) {
inputSnapshotBytes, err := history.GetInputSnapshot(ctx)
g.Expect(err).NotTo(HaveOccurred())

returnedData := map[string]interface{}{}
err = json.Unmarshal(inputSnapshotBytes, &returnedData)
g.Expect(err).NotTo(HaveOccurred())

gatewayKey := fmt.Sprintf("%s.%s", wellknown.GatewayGroup, wellknown.GatewayKind)
g.Expect(returnedData).To(HaveKey(gatewayKey), "Gateway should be included in input snap")

gatewayBytes, err := json.Marshal(returnedData[gatewayKey])
g.Expect(err).NotTo(HaveOccurred())

var gatewayList apiv1.GatewayList
err = json.Unmarshal(gatewayBytes, &gatewayList)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(gatewayList.Items).To(ContainElement(
WithTransform(func(gateway apiv1.Gateway) string {
return gateway.GetName()
}, Equal("gw-signal"))))
}).
WithPolling(time.Millisecond*100).
WithTimeout(time.Second*5).
Should(Succeed(), "setting client is asynchronous, so block until client is processed")
}
Loading