Skip to content

Commit

Permalink
adapt gomega.Eventually in E2E test
Browse files Browse the repository at this point in the history
Signed-off-by: changzhen <[email protected]>
  • Loading branch information
XiShanYongYe-Chang committed Oct 23, 2021
1 parent 531d6bf commit c360b37
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 66 deletions.
18 changes: 10 additions & 8 deletions test/e2e/fieldselector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,18 @@ var _ = ginkgo.Describe("propagation with fieldSelector testing", func() {
break
}
fmt.Printf("setting provider and region for cluster %v\n", cluster)
gomega.Eventually(func() error {
gomega.Eventually(func(g gomega.Gomega) {
clusterObj := &clusterv1alpha1.Cluster{}
err := controlPlaneClient.Get(context.TODO(), client.ObjectKey{Name: cluster}, clusterObj)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(err).NotTo(gomega.HaveOccurred())

originalClusterProviderInfo[cluster] = clusterObj.Spec.Provider
originalClusterRegionInfo[cluster] = clusterObj.Spec.Region
clusterObj.Spec.Provider = providerMap[index]
clusterObj.Spec.Region = regionMap[index]
return controlPlaneClient.Update(context.TODO(), clusterObj)
}, pollTimeout, pollInterval).ShouldNot(gomega.HaveOccurred())
err = controlPlaneClient.Update(context.TODO(), clusterObj)
g.Expect(err).NotTo(gomega.HaveOccurred())
}, pollTimeout, pollInterval).Should(gomega.Succeed())
}
})
})
Expand All @@ -91,15 +92,16 @@ var _ = ginkgo.Describe("propagation with fieldSelector testing", func() {
break
}

gomega.Eventually(func() error {
gomega.Eventually(func(g gomega.Gomega) {
clusterObj := &clusterv1alpha1.Cluster{}
err := controlPlaneClient.Get(context.TODO(), client.ObjectKey{Name: cluster}, clusterObj)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(err).NotTo(gomega.HaveOccurred())

clusterObj.Spec.Provider = originalClusterProviderInfo[cluster]
clusterObj.Spec.Region = originalClusterRegionInfo[cluster]
return controlPlaneClient.Update(context.TODO(), clusterObj)
}, pollTimeout, pollInterval).ShouldNot(gomega.HaveOccurred())
err = controlPlaneClient.Update(context.TODO(), clusterObj)
g.Expect(err).NotTo(gomega.HaveOccurred())
}, pollTimeout, pollInterval).Should(gomega.Succeed())
}
})
})
Expand Down
7 changes: 3 additions & 4 deletions test/e2e/framework/customresourcedefine.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ func WaitCRDPresentOnClusters(client karmada.Interface, clusters []string, crdAP
ginkgo.By(fmt.Sprintf("Check if crd(%s/%s) present on member clusters", crdAPIVersion, crdKind), func() {
for _, clusterName := range clusters {
klog.Infof("Waiting for crd present on cluster(%s)", clusterName)
gomega.Eventually(func() bool {
gomega.Eventually(func(g gomega.Gomega) (bool, error) {
cluster, err := fetchCluster(client, clusterName)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

return helper.IsAPIEnabled(cluster.Status.APIEnablements, crdAPIVersion, crdKind)
g.Expect(err).NotTo(gomega.HaveOccurred())
return helper.IsAPIEnabled(cluster.Status.APIEnablements, crdAPIVersion, crdKind), nil
}, pollTimeout, pollInterval).Should(gomega.Equal(true))
}
})
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/framework/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ func WaitDeploymentPresentOnClusters(clusters []string, namespace, name string)
gomega.Expect(clusterClient).ShouldNot(gomega.BeNil())

klog.Infof("Waiting for deployment present on cluster(%s)", clusterName)
gomega.Eventually(func() bool {
gomega.Eventually(func(g gomega.Gomega) (bool, error) {
_, err := clusterClient.AppsV1().Deployments(namespace).Get(context.TODO(), name, metav1.GetOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(err).NotTo(gomega.HaveOccurred())

return true
return true, nil
}, pollTimeout, pollInterval).Should(gomega.Equal(true))
}
})
Expand Down
42 changes: 21 additions & 21 deletions test/e2e/mcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,17 @@ var _ = ginkgo.Describe("[MCS] Multi-Cluster Service testing", func() {
})

ginkgo.By(fmt.Sprintf("Wait Service(%s/%s)'s EndpointSlice exist in %s cluster", demoService.Namespace, demoService.Name, serviceExportClusterName), func() {
gomega.Eventually(func() int {
gomega.Eventually(func(g gomega.Gomega) (int, error) {
endpointSlices, err := exportClusterClient.DiscoveryV1beta1().EndpointSlices(demoService.Namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: labels.Set{discoveryv1beta1.LabelServiceName: demoService.Name}.AsSelector().String(),
})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(err).NotTo(gomega.HaveOccurred())

epNums := 0
for _, slice := range endpointSlices.Items {
epNums += len(slice.Endpoints)
}
return epNums
return epNums, nil
}, pollTimeout, pollInterval).Should(gomega.Equal(1))
})
})
Expand Down Expand Up @@ -276,17 +276,17 @@ var _ = ginkgo.Describe("[MCS] Multi-Cluster Service testing", func() {
framework.CreatePropagationPolicy(karmadaClient, exportPolicy)

ginkgo.By(fmt.Sprintf("Wait EndpointSlices collected to namespace(%s) in controller-plane", demoService.Namespace), func() {
gomega.Eventually(func() int {
gomega.Eventually(func(g gomega.Gomega) (int, error) {
endpointSlices, err := kubeClient.DiscoveryV1beta1().EndpointSlices(demoService.Namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: labels.Set{discoveryv1beta1.LabelServiceName: names.GenerateDerivedServiceName(demoService.Name)}.AsSelector().String(),
})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(err).NotTo(gomega.HaveOccurred())

epNums := 0
for _, slice := range endpointSlices.Items {
epNums += len(slice.Endpoints)
}
return epNums
return epNums, nil
}, pollTimeout, pollInterval).Should(gomega.Equal(1))
})

Expand All @@ -312,17 +312,17 @@ var _ = ginkgo.Describe("[MCS] Multi-Cluster Service testing", func() {
})

ginkgo.By(fmt.Sprintf("Wait EndpointSlices have been imported to %s cluster", serviceImportClusterName), func() {
gomega.Eventually(func() int {
gomega.Eventually(func(g gomega.Gomega) (int, error) {
endpointSlices, err := importClusterClient.DiscoveryV1beta1().EndpointSlices(demoService.Namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: labels.Set{discoveryv1beta1.LabelServiceName: names.GenerateDerivedServiceName(demoService.Name)}.AsSelector().String(),
})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(err).NotTo(gomega.HaveOccurred())

epNums := 0
for _, slice := range endpointSlices.Items {
epNums += len(slice.Endpoints)
}
return epNums
return epNums, nil
}, pollTimeout, pollInterval).Should(gomega.Equal(1))
})

Expand Down Expand Up @@ -385,17 +385,17 @@ var _ = ginkgo.Describe("[MCS] Multi-Cluster Service testing", func() {
})

ginkgo.By(fmt.Sprintf("Wait Service(%s/%s)'s EndpointSlice exist in %s cluster", demoService.Namespace, demoService.Name, serviceExportClusterName), func() {
gomega.Eventually(func() int {
gomega.Eventually(func(g gomega.Gomega) (int, error) {
endpointSlices, err := exportClusterClient.DiscoveryV1beta1().EndpointSlices(demoService.Namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: labels.Set{discoveryv1beta1.LabelServiceName: demoService.Name}.AsSelector().String(),
})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(err).NotTo(gomega.HaveOccurred())

epNums := 0
for _, slice := range endpointSlices.Items {
epNums += len(slice.Endpoints)
}
return epNums
return epNums, nil
}, pollTimeout, pollInterval).Should(gomega.Equal(1))
})
})
Expand Down Expand Up @@ -429,17 +429,17 @@ var _ = ginkgo.Describe("[MCS] Multi-Cluster Service testing", func() {
framework.CreatePropagationPolicy(karmadaClient, exportPolicy)

ginkgo.By(fmt.Sprintf("Wait EndpointSlices collected to namespace(%s) in controller-plane", demoService.Namespace), func() {
gomega.Eventually(func() int {
gomega.Eventually(func(g gomega.Gomega) (int, error) {
endpointSlices, err := kubeClient.DiscoveryV1beta1().EndpointSlices(demoService.Namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: labels.Set{discoveryv1beta1.LabelServiceName: names.GenerateDerivedServiceName(demoService.Name)}.AsSelector().String(),
})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(err).NotTo(gomega.HaveOccurred())

epNums := 0
for _, slice := range endpointSlices.Items {
epNums += len(slice.Endpoints)
}
return epNums
return epNums, nil
}, pollTimeout, pollInterval).Should(gomega.Equal(1))
})

Expand All @@ -451,17 +451,17 @@ var _ = ginkgo.Describe("[MCS] Multi-Cluster Service testing", func() {
framework.CreatePropagationPolicy(karmadaClient, importPolicy)

ginkgo.By(fmt.Sprintf("Wait EndpointSlice exist in %s cluster", serviceImportClusterName), func() {
gomega.Eventually(func() int {
gomega.Eventually(func(g gomega.Gomega) (int, error) {
endpointSlices, err := importClusterClient.DiscoveryV1beta1().EndpointSlices(demoService.Namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: labels.Set{discoveryv1beta1.LabelServiceName: names.GenerateDerivedServiceName(demoService.Name)}.AsSelector().String(),
})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(err).NotTo(gomega.HaveOccurred())

epNums := 0
for _, slice := range endpointSlices.Items {
epNums += len(slice.Endpoints)
}
return epNums
return epNums, nil
}, pollTimeout, pollInterval).Should(gomega.Equal(1))
})

Expand All @@ -476,17 +476,17 @@ var _ = ginkgo.Describe("[MCS] Multi-Cluster Service testing", func() {
})

ginkgo.By(fmt.Sprintf("Wait EndpointSlice update in %s cluster", serviceImportClusterName), func() {
gomega.Eventually(func() int {
gomega.Eventually(func(g gomega.Gomega) (int, error) {
endpointSlices, err := importClusterClient.DiscoveryV1beta1().EndpointSlices(demoService.Namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: labels.Set{discoveryv1beta1.LabelServiceName: names.GenerateDerivedServiceName(demoService.Name)}.AsSelector().String(),
})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(err).NotTo(gomega.HaveOccurred())

epNums := 0
for _, slice := range endpointSlices.Items {
epNums += len(slice.Endpoints)
}
return epNums
return epNums, nil
}, pollTimeout, pollInterval).Should(gomega.Equal(2))
})

Expand Down
43 changes: 21 additions & 22 deletions test/e2e/scheduling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,13 @@ var _ = ginkgo.Describe("[ReplicaScheduling] ReplicaSchedulingStrategy testing",
clusterClient := framework.GetClusterClient(cluster.Name)
gomega.Expect(clusterClient).ShouldNot(gomega.BeNil())

gomega.Eventually(func() *int32 {
gomega.Eventually(func(g gomega.Gomega) (*int32, error) {
memberDeployment, err := clusterClient.AppsV1().Deployments(deploymentNamespace).Get(context.TODO(), deploymentName, metav1.GetOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(err).NotTo(gomega.HaveOccurred())

klog.Info(fmt.Sprintf("Deployment(%s/%s)'s replcas is %d on cluster(%s), expected: %d.",
deploymentNamespace, deploymentName, *memberDeployment.Spec.Replicas, cluster.Name, *deployment.Spec.Replicas))
return memberDeployment.Spec.Replicas
return memberDeployment.Spec.Replicas, nil
}, pollTimeout, pollInterval).Should(gomega.Equal(deployment.Spec.Replicas))
}
})
Expand Down Expand Up @@ -352,11 +352,10 @@ var _ = ginkgo.Describe("[ReplicaScheduling] ReplicaSchedulingStrategy testing",
clusterClient := framework.GetClusterClient(cluster.Name)
gomega.Expect(clusterClient).ShouldNot(gomega.BeNil())

gomega.Eventually(func() bool {
gomega.Eventually(func(g gomega.Gomega) (bool, error) {
_, err := clusterClient.AppsV1().Deployments(deploymentNamespace).Get(context.TODO(), deploymentName, metav1.GetOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

return true
g.Expect(err).NotTo(gomega.HaveOccurred())
return true, nil
}, pollTimeout, pollInterval).Should(gomega.Equal(true))
}
})
Expand All @@ -367,13 +366,13 @@ var _ = ginkgo.Describe("[ReplicaScheduling] ReplicaSchedulingStrategy testing",
clusterClient := framework.GetClusterClient(cluster.Name)
gomega.Expect(clusterClient).ShouldNot(gomega.BeNil())

gomega.Eventually(func() *int32 {
gomega.Eventually(func(g gomega.Gomega) (*int32, error) {
memberDeployment, err := clusterClient.AppsV1().Deployments(deploymentNamespace).Get(context.TODO(), deploymentName, metav1.GetOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(err).NotTo(gomega.HaveOccurred())

klog.Info(fmt.Sprintf("Deployment(%s/%s)'s replcas is %d on cluster(%s), expected: %d.",
deploymentNamespace, deploymentName, *memberDeployment.Spec.Replicas, cluster.Name, *deployment.Spec.Replicas))
return memberDeployment.Spec.Replicas
return memberDeployment.Spec.Replicas, nil
}, pollTimeout, pollInterval).Should(gomega.Equal(deployment.Spec.Replicas))
}
})
Expand Down Expand Up @@ -420,13 +419,13 @@ var _ = ginkgo.Describe("[ReplicaScheduling] ReplicaSchedulingStrategy testing",
clusterClient := framework.GetClusterClient(cluster.Name)
gomega.Expect(clusterClient).ShouldNot(gomega.BeNil())

gomega.Eventually(func() int32 {
gomega.Eventually(func(g gomega.Gomega) (int32, error) {
memberDeployment, err := clusterClient.AppsV1().Deployments(deploymentNamespace).Get(context.TODO(), deploymentName, metav1.GetOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(err).NotTo(gomega.HaveOccurred())

klog.Info(fmt.Sprintf("Deployment(%s/%s)'s replcas is %d on cluster(%s), expected: %d.",
deploymentNamespace, deploymentName, *memberDeployment.Spec.Replicas, cluster.Name, expectedReplicas))
return *memberDeployment.Spec.Replicas
return *memberDeployment.Spec.Replicas, nil
}, pollTimeout, pollInterval).Should(gomega.Equal(expectedReplicas))
}
})
Expand Down Expand Up @@ -476,13 +475,13 @@ var _ = ginkgo.Describe("[ReplicaScheduling] ReplicaSchedulingStrategy testing",
clusterClient := framework.GetClusterClient(cluster.Name)
gomega.Expect(clusterClient).ShouldNot(gomega.BeNil())

gomega.Eventually(func() int32 {
gomega.Eventually(func(g gomega.Gomega) (int32, error) {
memberDeployment, err := clusterClient.AppsV1().Deployments(deploymentNamespace).Get(context.TODO(), deploymentName, metav1.GetOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(err).NotTo(gomega.HaveOccurred())

klog.Info(fmt.Sprintf("Deployment(%s/%s)'s replcas is %d on cluster(%s), expected: %d.",
deploymentNamespace, deploymentName, *memberDeployment.Spec.Replicas, cluster.Name, expectedReplicas))
return *memberDeployment.Spec.Replicas
return *memberDeployment.Spec.Replicas, nil
}, pollTimeout, pollInterval).Should(gomega.Equal(expectedReplicas))
}
})
Expand Down Expand Up @@ -547,13 +546,13 @@ var _ = ginkgo.Describe("[ReplicaScheduling] ReplicaSchedulingStrategy testing",
clusterClient := framework.GetClusterClient(cluster.Name)
gomega.Expect(clusterClient).ShouldNot(gomega.BeNil())

gomega.Eventually(func() int32 {
gomega.Eventually(func(g gomega.Gomega) (int32, error) {
memberDeployment, err := clusterClient.AppsV1().Deployments(deploymentNamespace).Get(context.TODO(), deploymentName, metav1.GetOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(err).NotTo(gomega.HaveOccurred())

klog.Info(fmt.Sprintf("Deployment(%s/%s)'s replcas is %d on cluster(%s), expected: %d.",
deploymentNamespace, deploymentName, *memberDeployment.Spec.Replicas, cluster.Name, expectedReplicas))
return *memberDeployment.Spec.Replicas
return *memberDeployment.Spec.Replicas, nil
}, pollTimeout, pollInterval).Should(gomega.Equal(expectedReplicas))
}
})
Expand Down Expand Up @@ -637,13 +636,13 @@ var _ = ginkgo.Describe("[ReplicaScheduling] ReplicaSchedulingStrategy testing",
clusterClient := framework.GetClusterClient(cluster.Name)
gomega.Expect(clusterClient).ShouldNot(gomega.BeNil())

gomega.Eventually(func() int32 {
gomega.Eventually(func(g gomega.Gomega) (int32, error) {
memberDeployment, err := clusterClient.AppsV1().Deployments(deploymentNamespace).Get(context.TODO(), deploymentName, metav1.GetOptions{})
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(err).NotTo(gomega.HaveOccurred())

klog.Info(fmt.Sprintf("Deployment(%s/%s)'s replcas is %d on cluster(%s), expected: %d.",
deploymentNamespace, deploymentName, *memberDeployment.Spec.Replicas, cluster.Name, expectedReplicas))
return *memberDeployment.Spec.Replicas
return *memberDeployment.Spec.Replicas, nil
}, pollTimeout, pollInterval).Should(gomega.Equal(expectedReplicas))
}
})
Expand Down
16 changes: 8 additions & 8 deletions test/e2e/tainttoleration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ var _ = ginkgo.Describe("propagation with taint and toleration testing", func()
for _, clusterName := range framework.ClusterNames() {
taints := constructAddedTaints(tolerationKey, clusterName)

gomega.Eventually(func() bool {
gomega.Eventually(func(g gomega.Gomega) (bool, error) {
clusterObj := &clusterv1alpha1.Cluster{}
err := controlPlaneClient.Get(context.TODO(), client.ObjectKey{Name: clusterName}, clusterObj)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(err).NotTo(gomega.HaveOccurred())

clusterObj.Spec.Taints = append(clusterObj.Spec.Taints, taints...)
klog.Infof("update taints(%s) of cluster(%s)", clusterObj.Spec.Taints, clusterName)

err = controlPlaneClient.Update(context.TODO(), clusterObj)
if err != nil {
klog.Errorf("Failed to update cluster(%s), err: %v", clusterName, err)
return false
return false, err
}
return true
return true, nil
}, pollTimeout, pollInterval).Should(gomega.Equal(true))
}
})
Expand All @@ -77,20 +77,20 @@ var _ = ginkgo.Describe("propagation with taint and toleration testing", func()
ginkgo.AfterEach(func() {
ginkgo.By("removing taints in cluster", func() {
for _, clusterName := range framework.ClusterNames() {
gomega.Eventually(func() bool {
gomega.Eventually(func(g gomega.Gomega) (bool, error) {
clusterObj := &clusterv1alpha1.Cluster{}
err := controlPlaneClient.Get(context.TODO(), client.ObjectKey{Name: clusterName}, clusterObj)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(err).NotTo(gomega.HaveOccurred())

clusterObj.Spec.Taints = removeTargetFromSource(clusterObj.Spec.Taints, constructAddedTaints(tolerationKey, clusterName))
klog.Infof("update taints(%s) of cluster(%s)", clusterObj.Spec.Taints, clusterName)

err = controlPlaneClient.Update(context.TODO(), clusterObj)
if err != nil {
klog.Errorf("Failed to update cluster(%s), err: %v", clusterName, err)
return false
return false, err
}
return true
return true, nil
}, pollTimeout, pollInterval).Should(gomega.Equal(true))
}
})
Expand Down

0 comments on commit c360b37

Please sign in to comment.