Skip to content

Commit 25fba24

Browse files
author
Arvind Thirumurugan
committed
address comments
1 parent f0c92d4 commit 25fba24

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

test/e2e/drain_tool_test.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ var _ = Describe("Drain cluster successfully", Ordered, Serial, func() {
4040
var drainEvictions []placementv1beta1.ClusterResourcePlacementEviction
4141
var drainClusters, noDrainClusters []*framework.Cluster
4242
var noDrainClusterNames []string
43+
var testStartTime time.Time
4344

4445
BeforeAll(func() {
46+
testStartTime = time.Now()
4547
drainClusters = []*framework.Cluster{memberCluster1EastProd}
4648
noDrainClusters = []*framework.Cluster{memberCluster2EastCanary, memberCluster3WestProd}
4749
noDrainClusterNames = []string{memberCluster2EastCanaryName, memberCluster3WestProdName}
@@ -79,8 +81,8 @@ var _ = Describe("Drain cluster successfully", Ordered, Serial, func() {
7981

8082
It("should update drain cluster resource placement evictions status as expected", func() {
8183
var fetchError error
82-
drainEvictions, fetchError = fetchDrainEvictions(crpName, memberCluster1EastProdName)
83-
Eventually(fetchError).Should(Succeed(), "Failed to fetch drain evictions")
84+
drainEvictions, fetchError = fetchDrainEvictions(crpName, memberCluster1EastProdName, testStartTime)
85+
Expect(fetchError).Should(Succeed(), "Failed to fetch drain evictions")
8486
for _, eviction := range drainEvictions {
8587
crpEvictionStatusUpdatedActual := testutilseviction.StatusUpdatedActual(
8688
ctx, hubClient, eviction.Name,
@@ -121,8 +123,10 @@ var _ = Describe("Drain cluster successfully", Ordered, Serial, func() {
121123
var _ = Describe("Drain cluster blocked - ClusterResourcePlacementDisruptionBudget blocks evictions on all clusters", Ordered, Serial, func() {
122124
crpName := fmt.Sprintf(crpNameTemplate, GinkgoParallelProcess())
123125
var drainEvictions []placementv1beta1.ClusterResourcePlacementEviction
126+
var testStartTime time.Time
124127

125128
BeforeAll(func() {
129+
testStartTime = time.Now()
126130
By("creating work resources")
127131
createWorkResources()
128132

@@ -172,8 +176,8 @@ var _ = Describe("Drain cluster blocked - ClusterResourcePlacementDisruptionBudg
172176

173177
It("should update drain cluster resource placement evictions status as expected", func() {
174178
var fetchError error
175-
drainEvictions, fetchError = fetchDrainEvictions(crpName, memberCluster1EastProdName)
176-
Eventually(fetchError).Should(Succeed(), "Failed to fetch drain evictions")
179+
drainEvictions, fetchError = fetchDrainEvictions(crpName, memberCluster1EastProdName, testStartTime)
180+
Expect(fetchError).Should(Succeed(), "Failed to fetch drain evictions")
177181
for _, eviction := range drainEvictions {
178182
crpEvictionStatusUpdatedActual := testutilseviction.StatusUpdatedActual(
179183
ctx, hubClient, eviction.Name,
@@ -204,8 +208,10 @@ var _ = Describe("Drain is allowed on one cluster, blocked on others - ClusterRe
204208
var drainEvictions []placementv1beta1.ClusterResourcePlacementEviction
205209
var drainClusters, noDrainClusters []*framework.Cluster
206210
var noDrainClusterNames []string
211+
var testStartTime time.Time
207212

208213
BeforeAll(func() {
214+
testStartTime = time.Now()
209215
drainClusters = []*framework.Cluster{memberCluster1EastProd}
210216
noDrainClusters = []*framework.Cluster{memberCluster2EastCanary, memberCluster3WestProd}
211217
noDrainClusterNames = []string{memberCluster2EastCanaryName, memberCluster3WestProdName}
@@ -259,8 +265,8 @@ var _ = Describe("Drain is allowed on one cluster, blocked on others - ClusterRe
259265

260266
It("should update drain cluster resource placement evictions status as expected", func() {
261267
var fetchError error
262-
drainEvictions, fetchError = fetchDrainEvictions(crpName, memberCluster1EastProdName)
263-
Eventually(fetchError).Should(Succeed(), "Failed to fetch drain evictions")
268+
drainEvictions, fetchError = fetchDrainEvictions(crpName, memberCluster1EastProdName, testStartTime)
269+
Expect(fetchError).Should(Succeed(), "Failed to fetch drain evictions")
264270
for _, eviction := range drainEvictions {
265271
crpEvictionStatusUpdatedActual := testutilseviction.StatusUpdatedActual(
266272
ctx, hubClient, eviction.Name,
@@ -285,8 +291,8 @@ var _ = Describe("Drain is allowed on one cluster, blocked on others - ClusterRe
285291

286292
It("should update drain cluster resource placement evictions status as expected", func() {
287293
var fetchError error
288-
drainEvictions, fetchError = fetchDrainEvictions(crpName, memberCluster2EastCanaryName)
289-
Eventually(fetchError).Should(Succeed(), "Failed to fetch drain evictions")
294+
drainEvictions, fetchError = fetchDrainEvictions(crpName, memberCluster2EastCanaryName, testStartTime)
295+
Expect(fetchError).Should(Succeed(), "Failed to fetch drain evictions")
290296
for _, eviction := range drainEvictions {
291297
crpEvictionStatusUpdatedActual := testutilseviction.StatusUpdatedActual(
292298
ctx, hubClient, eviction.Name,
@@ -349,15 +355,14 @@ func runUncordonClusterBinary(hubClusterName, memberClusterName string) {
349355
Expect(err).ToNot(HaveOccurred(), "Uncordon command failed with error: %v", err)
350356
}
351357

352-
func fetchDrainEvictions(crpName, clusterName string) ([]placementv1beta1.ClusterResourcePlacementEviction, error) {
358+
func fetchDrainEvictions(crpName, clusterName string, testStartTime time.Time) ([]placementv1beta1.ClusterResourcePlacementEviction, error) {
353359
var evictionList placementv1beta1.ClusterResourcePlacementEvictionList
354360
if err := hubClient.List(ctx, &evictionList); err != nil {
355361
return nil, err
356362
}
357363
var filteredDrainEvictions []placementv1beta1.ClusterResourcePlacementEviction
358-
thirtySecondsAgo := time.Now().Add(-30 * time.Second)
359364
for _, eviction := range evictionList.Items {
360-
if eviction.CreationTimestamp.Time.After(thirtySecondsAgo) &&
365+
if eviction.CreationTimestamp.Time.After(testStartTime) &&
361366
eviction.Spec.PlacementName == crpName &&
362367
eviction.Spec.ClusterName == clusterName {
363368
filteredDrainEvictions = append(filteredDrainEvictions, eviction)

0 commit comments

Comments
 (0)