Skip to content

Commit 327e93e

Browse files
authored
Merge pull request #1161 from keynslug/test/e2e/ds-enable-on-running
test(e2e): verify enabling DS on existing instance
2 parents 7f62a02 + d36b920 commit 327e93e

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

test/e2e/emqx_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,4 +589,78 @@ var _ = Describe("EMQX Test", Label("emqx"), Ordered, func() {
589589
})
590590

591591
})
592+
593+
Context("EMQX Core-Replicant Cluster / Runtime-enabled DS Replication", func() {
594+
// Initial number of core and replicant replicas:
595+
var coreReplicas int = 1
596+
var replicantReplicas int = 2
597+
598+
It("deploy core-replicant EMQX cluster", func() {
599+
By("create EMQX cluster")
600+
emqxCR := PatchDocument(
601+
FromYAMLFile(emqxCRBasic),
602+
withImage(emqxImage),
603+
withCores(coreReplicas),
604+
withReplicants(replicantReplicas),
605+
withConfig(),
606+
)
607+
Expect(KubectlStdin(emqxCR, "apply", "-f", "-")).To(Succeed())
608+
609+
By("wait for EMQX cluster to be ready")
610+
Eventually(checkEMQXReady).Should(Succeed())
611+
Eventually(checkEMQXStatus).WithArguments(coreReplicas).Should(Succeed())
612+
Eventually(checkReplicantStatus).WithArguments(replicantReplicas).Should(Succeed())
613+
})
614+
615+
It("enable DS replication", func() {
616+
By("change config + add label to trigger new deployment")
617+
configDs := string(intoJsonString(configDS()))
618+
coreReplicas = 2
619+
changedAt := metav1.Now()
620+
Expect(Kubectl("patch", "emqx", "emqx",
621+
"--type", "json",
622+
"--patch", `[
623+
{"op": "replace", "path": "/spec/config/data", "value": `+configDs+`},
624+
{"op": "add", "path": "/spec/coreTemplate/metadata/labels", "value": {"e2e/ds-replication": "true"}},
625+
{"op": "replace", "path": "/spec/coreTemplate/spec/replicas", "value": 2}
626+
]`,
627+
)).To(Succeed())
628+
629+
By("wait for EMQX cluster to become ready again")
630+
Eventually(checkEMQXReady).WithArguments(changedAt).Should(Succeed())
631+
Eventually(checkEMQXStatus).WithArguments(coreReplicas).Should(Succeed())
632+
Eventually(checkReplicantStatus).WithArguments(replicantReplicas).Should(Succeed())
633+
Eventually(checkDSReplicationStatus).WithArguments(coreReplicas).Should(Succeed())
634+
// EMQX 5.10.1: Initial cluster's sites are expected to hang around.
635+
// Eventually(checkDSReplicationHealthy).Should(Succeed())
636+
637+
By("verify EMQX pods have relevant conditions")
638+
var pods corev1.PodList
639+
Expect(KubectlOut("get", "pods",
640+
"--selector", crdv2.LabelManagedBy+"=emqx-operator",
641+
"-o", "json",
642+
)).To(UnmarshalInto(&pods), "Failed to list EMQX pods")
643+
Expect(pods.Items).To(HaveLen(4))
644+
for _, pod := range pods.Items {
645+
if pod.Labels[crdv2.LabelDBRole] == "core" {
646+
Expect(pod.Status.Conditions).To(ContainElement(And(
647+
HaveField("Type", Equal(crdv2.DSReplicationSite)),
648+
HaveField("Status", Equal(corev1.ConditionTrue)),
649+
)))
650+
}
651+
if pod.Labels[crdv2.LabelDBRole] == "replicant" {
652+
Expect(pod.Status.Conditions).To(ContainElement(And(
653+
HaveField("Type", Equal(crdv2.DSReplicationSite)),
654+
HaveField("Status", Equal(corev1.ConditionFalse)),
655+
)))
656+
}
657+
}
658+
})
659+
660+
It("delete EMQX cluster", func() {
661+
Expect(Kubectl("delete", "emqx", "emqx")).To(Succeed())
662+
Expect(Kubectl("get", "emqx", "emqx")).To(HaveOccurred(), "EMQX cluster still exists")
663+
})
664+
665+
})
592666
})

0 commit comments

Comments
 (0)