Skip to content

Commit

Permalink
Harden backwards compatibility tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thegridman committed Oct 18, 2023
1 parent 7ab271d commit 5d5b276
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
24 changes: 14 additions & 10 deletions test/e2e/compatibility/compatibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ func TestCompatibility(t *testing.T) {
helper.DumpState(testContext, ns, dir)

// Upgrade to this version
t.Logf("Helm upgrade to current Operator version\n")
UpgradeToCurrentVersion(g, ns, name)
UpgradeToCurrentVersion(t, g, ns, name)

// wait a few minutes to allow the new Operator to reconcile the existing Coherence cluster
t.Logf("Upgraded to current Operator version - waiting for reconcile...\n")
time.Sleep(2 * time.Minute)
time.Sleep(1 * time.Minute)

// Get the current state of the StatefulSet
stsAfter := &appsv1.StatefulSet{}
Expand All @@ -78,8 +77,9 @@ func TestCompatibility(t *testing.T) {
g.Expect(stsAfter.Generation).To(Equal(stsBefore.Generation))

// scale up to make sure that the Operator can still manage the Coherence cluster
t.Logf("Scaling coherence resource %s in namespace %s to 3 replicas", ns, d.Name)
cmd := exec.Command("kubectl", "-n", ns, "scale", "coherence", d.Name, "--replicas=3")
n := fmt.Sprintf("coherence/%s", d.Name)
t.Logf("Scaling coherence resource %s in namespace %s to 3 replicas\n", n, ns)
cmd := exec.Command("kubectl", "-n", ns, "scale", n, "--replicas=3")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
Expand Down Expand Up @@ -121,14 +121,15 @@ func InstallPreviousVersion(g *GomegaWithT, ns, name, version, selector string)
err = cmd.Run()
g.Expect(err).NotTo(HaveOccurred())

pods, err := helper.WaitForPodsWithSelector(testContext, ns, selector, time.Second*10, time.Minute*5)
replicas := values.GetReplicas(1)
pods, err := helper.WaitForPodsWithSelectorAndReplicas(testContext, ns, selector, replicas, time.Second*10, time.Minute*5)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(len(pods)).To(Equal(values.GetReplicas(1)))
err = helper.WaitForPodReady(testContext, ns, pods[0].Name, time.Second*10, time.Minute*5)
g.Expect(err).NotTo(HaveOccurred())
}

func UpgradeToCurrentVersion(g *GomegaWithT, ns, name string) {
func UpgradeToCurrentVersion(t *testing.T, g *GomegaWithT, ns, name string) {
t.Logf("Helm upgrade to current Operator version\n")
chart, err := helper.FindOperatorHelmChartDir()
g.Expect(err).NotTo(HaveOccurred())

Expand All @@ -138,15 +139,18 @@ func UpgradeToCurrentVersion(g *GomegaWithT, ns, name string) {
"--namespace", ns, "--wait", name, chart)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
t.Logf("Helm upgrade to current Operator version - executing Helm upgrade\n")
err = cmd.Run()
g.Expect(err).NotTo(HaveOccurred())
t.Logf("Helm upgrade to current Operator version - Helm upgrade successful\n")

version := os.Getenv("VERSION")
selector := "app.kubernetes.io/version=" + version

pods, err := helper.WaitForPodsWithSelector(testContext, ns, selector, time.Second*10, time.Minute*5)
t.Logf("Helm upgrade to current Operator version - Waiting for pods in namespace %s with selector \"%s\"\n", ns, selector)
pods, err := helper.WaitForPodsWithSelectorAndReplicas(testContext, ns, selector, 3, time.Second*10, time.Minute*5)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(len(pods)).To(Equal(3))
t.Logf("Helm upgrade to current Operator version - Waiting for Pods %s in namespace %s to be ready\n", pods[0].Name, ns)
err = helper.WaitForPodReady(testContext, ns, pods[0].Name, time.Second*10, time.Minute*5)
g.Expect(err).NotTo(HaveOccurred())
}
Expand Down
14 changes: 14 additions & 0 deletions test/e2e/helper/e2e-helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,20 @@ func WaitForPodsWithSelector(ctx TestContext, namespace, selector string, retryI
return pods, err
}

// WaitForPodsWithSelectorAndReplicas waits for Pods to be created.
func WaitForPodsWithSelectorAndReplicas(ctx TestContext, namespace, selector string, replicas int, retryInterval, timeout time.Duration) ([]corev1.Pod, error) {
var pods []corev1.Pod

err := wait.PollUntilContextTimeout(ctx.Context, retryInterval, timeout, true, func(context.Context) (done bool, err error) {
pods, err = ListPodsWithLabelSelector(ctx, namespace, selector)
if err != nil {
return false, err
}
return len(pods) == replicas, nil
})
return pods, err
}

// WaitForOperatorDeletion waits for deletion of the Operator Pods.
//
//goland:noinspection GoUnusedExportedFunction
Expand Down

0 comments on commit 5d5b276

Please sign in to comment.