Skip to content

Commit

Permalink
fix primary failover test
Browse files Browse the repository at this point in the history
Signed-off-by: UMEZAWA Takeshi <takeshi-umezawa@cybozu.co.jp>
  • Loading branch information
umezawatakeshi authored and kfyharukz committed Nov 5, 2020
1 parent 720fe05 commit 8810530
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions e2e/primary_failover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,30 @@ func testPrimaryFailOver() {

By("checking cluster status")
Eventually(func() error {
/*
* The condition may not become unhealthy immediately after deleting pod.
* So, the following `findCondition` may observe healthy before primary switching.
* On the other hand, it is not guaranteed to observe the unhealthy condition.
*
* Consequently, `Eventually` block must contain both condition check and primary index check.
*/
cluster, err = getMySQLCluster()
healthy := findCondition(cluster.Status.Conditions, v1alpha1.ConditionHealthy)
if healthy == nil || healthy.Status != corev1.ConditionTrue {
return errors.New("should recover")
}

if cluster.Status.CurrentPrimaryIndex == nil {
return errors.New("current primary index is unknown")
}
newPrimary := *cluster.Status.CurrentPrimaryIndex
if newPrimary == firstPrimary {
return fmt.Errorf("current primary is still %d", firstPrimary)
}

return nil
}, 2*time.Minute).Should(Succeed())

Expect(cluster.Status.CurrentPrimaryIndex).ShouldNot(BeNil())
newPrimary := *cluster.Status.CurrentPrimaryIndex
Expect(newPrimary).ShouldNot(Equal(firstPrimary))

By("connecting to recovered instance")
connector.stopPortForward()
err = connector.startPortForward()
Expand Down

0 comments on commit 8810530

Please sign in to comment.