Skip to content

Commit 1408f03

Browse files
wadlejitendrajsilvelaarmru
authored
test(e2e): skip test suite if operator was restarted or renamed
This is in preparation for the open source release of Cloud Native PostgreSQL. Co-authored-by: Jaime Silvela <jaime.silvela@enterprisedb.com> Co-authored-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
1 parent d0aba0d commit 1408f03

File tree

3 files changed

+50
-21
lines changed

3 files changed

+50
-21
lines changed

tests/e2e/asserts_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -305,21 +305,6 @@ func AssertConnection(host string, user string, dbname string,
305305
})
306306
}
307307

308-
// AssertOperatorPodUnchanged verifies that the pod has an expected name and never restarted
309-
func AssertOperatorPodUnchanged(expectedOperatorPodName string) {
310-
operatorPod, err := env.GetOperatorPod()
311-
Expect(err).NotTo(HaveOccurred())
312-
Expect(operatorPod.GetName()).Should(BeEquivalentTo(expectedOperatorPodName),
313-
"Operator pod was recreated before the end of the test")
314-
restartCount := -1
315-
for _, containerStatus := range operatorPod.Status.ContainerStatuses {
316-
if containerStatus.Name == "manager" {
317-
restartCount = int(containerStatus.RestartCount)
318-
}
319-
}
320-
Expect(restartCount).Should(BeEquivalentTo(0), fmt.Sprintf("Operator pod get restarted %v times ", restartCount))
321-
}
322-
323308
// AssertOperatorIsReady verifies that the operator is ready
324309
func AssertOperatorIsReady() {
325310
Eventually(func() (bool, error) {

tests/e2e/suite_test.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ var (
3535
env *utils.TestingEnvironment
3636
testLevelEnv *tests.TestEnvLevel
3737
expectedOperatorPodName string
38+
operatorPodWasRenamed bool
39+
operatorWasRestarted bool
3840
)
3941

4042
var _ = BeforeSuite(func() {
@@ -55,11 +57,22 @@ var _ = BeforeEach(func() {
5557
labelsForTestsBreakingTheOperator := []string{"upgrade", "disruptive"}
5658
breakingLabelsInCurrentTest := funk.Join(CurrentSpecReport().Labels(),
5759
labelsForTestsBreakingTheOperator, funk.InnerJoin)
58-
if len(breakingLabelsInCurrentTest.([]string)) == 0 {
59-
operatorPod, err := env.GetOperatorPod()
60-
Expect(err).NotTo(HaveOccurred())
61-
expectedOperatorPodName = operatorPod.GetName()
60+
61+
if len(breakingLabelsInCurrentTest.([]string)) != 0 {
62+
return
63+
}
64+
65+
operatorPod, err := env.GetOperatorPod()
66+
Expect(err).ToNot(HaveOccurred())
67+
68+
if operatorPodWasRenamed {
69+
Skip("Skipping test. Operator was renamed")
70+
}
71+
if operatorWasRestarted {
72+
Skip("Skipping test. Operator was restarted")
6273
}
74+
75+
expectedOperatorPodName = operatorPod.GetName()
6376
})
6477

6578
func TestE2ESuite(t *testing.T) {
@@ -70,11 +83,26 @@ func TestE2ESuite(t *testing.T) {
7083

7184
// Before the end of the tests we should verify that the operator never restarted
7285
// and that the operator pod name didn't change.
86+
// If either of those things happened, the test will fail, and all subsequent
87+
// tests will be SKIPPED, as they would always fail in this node.
7388
var _ = AfterEach(func() {
7489
labelsForTestsBreakingTheOperator := []string{"upgrade", "disruptive"}
7590
breakingLabelsInCurrentTest := funk.Join(CurrentSpecReport().Labels(),
7691
labelsForTestsBreakingTheOperator, funk.InnerJoin)
77-
if len(breakingLabelsInCurrentTest.([]string)) == 0 {
78-
AssertOperatorPodUnchanged(expectedOperatorPodName)
92+
if len(breakingLabelsInCurrentTest.([]string)) != 0 {
93+
return
94+
}
95+
operatorPod, err := env.GetOperatorPod()
96+
Expect(err).ToNot(HaveOccurred())
97+
98+
wasRenamed := utils.OperatorPodRenamed(operatorPod, expectedOperatorPodName)
99+
if wasRenamed {
100+
operatorPodWasRenamed = true
101+
Fail("operator was renamed")
102+
}
103+
wasRestarted := utils.OperatorPodRestarted(operatorPod)
104+
if wasRestarted {
105+
operatorWasRestarted = true
106+
Fail("operator was restarted")
79107
}
80108
})

tests/utils/operator.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,19 @@ func (env TestingEnvironment) IsOperatorReady() (bool, error) {
235235

236236
return true, err
237237
}
238+
239+
// OperatorPodRenamed checks if the operator pod was renamed
240+
func OperatorPodRenamed(operatorPod corev1.Pod, expectedOperatorPodName string) bool {
241+
return operatorPod.GetName() != expectedOperatorPodName
242+
}
243+
244+
// OperatorPodRestarted checks if the operator pod was restarted
245+
func OperatorPodRestarted(operatorPod corev1.Pod) bool {
246+
restartCount := 0
247+
for _, containerStatus := range operatorPod.Status.ContainerStatuses {
248+
if containerStatus.Name == "manager" {
249+
restartCount = int(containerStatus.RestartCount)
250+
}
251+
}
252+
return restartCount != 0
253+
}

0 commit comments

Comments
 (0)