Skip to content

Commit 559a636

Browse files
committed
Fix e2e2 Ctrl+C cleanup
1 parent 6396404 commit 559a636

File tree

4 files changed

+42
-27
lines changed

4 files changed

+42
-27
lines changed

test/e2e2/ako_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ var _ = Describe("Atlas Operator Start and Stop test", Ordered, Label("ako-start
4848
ako = runTestAKO(DefaultGlobalCredentials, control.MustEnvVar("OPERATOR_NAMESPACE"), deletionProtectionOff)
4949
ako.Start(GinkgoT())
5050

51+
// Register cleanup - this should even when the process is interrupted with Ctrl+C
52+
// AfterAll is not reliable in such cases.
53+
DeferCleanup(func() {
54+
if ako != nil {
55+
ako.Stop(GinkgoT())
56+
}
57+
})
58+
5159
ctx = context.Background()
5260
client, err := kube.NewTestClient()
5361
Expect(err).To(Succeed())
@@ -57,10 +65,6 @@ var _ = Describe("Atlas Operator Start and Stop test", Ordered, Label("ako-start
5765
})).To(Succeed())
5866
})
5967

60-
_ = AfterAll(func() {
61-
ako.Stop(GinkgoT())
62-
})
63-
6468
_ = BeforeEach(func() {
6569
testNamespace = &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{
6670
Name: utils.RandomName("ako-ns"),

test/e2e2/flex_to_dedicated_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,20 @@ var _ = Describe("Flex to Dedicated Upgrade", Ordered, Label("flex-to-dedicated"
5151
ako = runTestAKO(DefaultGlobalCredentials, control.MustEnvVar("OPERATOR_NAMESPACE"), false)
5252
ako.Start(GinkgoT())
5353

54+
// Register cleanup - this should even when the process is interrupted with Ctrl+C
55+
// AfterAll is not reliable in such cases.
56+
DeferCleanup(func() {
57+
if ako != nil {
58+
ako.Stop(GinkgoT())
59+
}
60+
})
61+
5462
ctx = context.Background()
5563
client, err := kube.NewTestClient()
5664
Expect(err).ToNot(HaveOccurred())
5765
kubeClient = client
5866
})
5967

60-
_ = AfterAll(func() {
61-
if ako != nil {
62-
ako.Stop(GinkgoT())
63-
}
64-
})
65-
6668
_ = BeforeEach(func() {
6769
resourcePrefix = utils.RandomName("flex-to-dedicated")
6870
testNamespace = &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{

test/e2e2/flexcluster_test.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ var _ = Describe("FlexCluster CRUD", Ordered, Label("flexcluster-ctlr"), func()
7272
ako = runTestAKO(DefaultGlobalCredentials, control.MustEnvVar("OPERATOR_NAMESPACE"), deletionProtectionOff)
7373
ako.Start(GinkgoT())
7474

75+
// Register cleanup - this should even when the process is interrupted with Ctrl+C
76+
// AfterAll is not reliable in such cases.
77+
DeferCleanup(func() {
78+
if ako != nil {
79+
ako.Stop(GinkgoT())
80+
}
81+
})
82+
7583
testClient, err := kube.NewTestClient()
7684
Expect(err).To(Succeed())
7785
kubeClient = testClient
@@ -113,26 +121,25 @@ var _ = Describe("FlexCluster CRUD", Ordered, Label("flexcluster-ctlr"), func()
113121
})
114122

115123
_ = AfterAll(func(ctx context.Context) {
116-
if kubeClient != nil && testGroup != nil {
117-
By("Clean up test Group", func() {
124+
By("Clean up test Group", func() {
125+
if kubeClient != nil && testGroup != nil {
126+
118127
Expect(kubeClient.Delete(ctx, testGroup)).To(Succeed())
119128
Eventually(func(g Gomega) error {
120129
err := kubeClient.Get(ctx, client.ObjectKeyFromObject(testGroup), testGroup)
121130
return err
122131
}).WithContext(ctx).WithTimeout(5 * time.Minute).WithPolling(5 * time.Second).NotTo(Succeed())
123-
})
124-
}
125-
if kubeClient != nil && sharedGroupNamespace != nil {
126-
By("Clean up shared group namespace", func() {
132+
}
133+
})
134+
By("Clean up shared group namespace", func() {
135+
if kubeClient != nil && sharedGroupNamespace != nil {
136+
127137
Expect(kubeClient.Delete(ctx, sharedGroupNamespace)).To(Succeed())
128138
Eventually(func(g Gomega) bool {
129139
return kubeClient.Get(ctx, client.ObjectKeyFromObject(sharedGroupNamespace), sharedGroupNamespace) == nil
130140
}).WithContext(ctx).WithTimeout(time.Minute).WithPolling(time.Second).To(BeFalse())
131-
})
132-
}
133-
if ako != nil {
134-
ako.Stop(GinkgoT())
135-
}
141+
}
142+
})
136143
})
137144

138145
_ = BeforeEach(func(ctx context.Context) {

test/e2e2/integration_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ var _ = Describe("Atlas Third-Party Integrations Controller", Ordered, Label("in
5858
ako = runTestAKO(DefaultGlobalCredentials, control.MustEnvVar("OPERATOR_NAMESPACE"), deletionProtectionOff)
5959
ako.Start(GinkgoT())
6060

61+
// Register cleanup - this should even when the process is interrupted with Ctrl+C
62+
// AfterAll is not reliable in such cases.
63+
DeferCleanup(func() {
64+
if ako != nil {
65+
ako.Stop(GinkgoT())
66+
}
67+
})
68+
6169
ctx = context.Background()
6270
client, err := kube.NewTestClient()
6371
Expect(err).To(Succeed())
@@ -67,12 +75,6 @@ var _ = Describe("Atlas Third-Party Integrations Controller", Ordered, Label("in
6775
})).To(Succeed())
6876
})
6977

70-
_ = AfterAll(func() {
71-
if ako != nil {
72-
ako.Stop(GinkgoT())
73-
}
74-
})
75-
7678
_ = BeforeEach(func() {
7779
testNamespace = &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{
7880
Name: utils.RandomName("integrations-ctlr-ns"),

0 commit comments

Comments
 (0)