|
4 | 4 | _ "embed" |
5 | 5 | "errors" |
6 | 6 | "fmt" |
7 | | - |
8 | 7 | mocov1beta2 "github.com/cybozu-go/moco/api/v1beta2" |
9 | 8 | . "github.com/onsi/ginkgo/v2" |
10 | 9 | . "github.com/onsi/gomega" |
@@ -95,6 +94,47 @@ var _ = Context("switchover", Ordered, func() { |
95 | 94 | }).Should(Succeed()) |
96 | 95 | }) |
97 | 96 |
|
| 97 | + It("should switch the primary if requested, even when a holding global read lock exceeds timeout", func() { |
| 98 | + cluster, err := getCluster("switchover", "test") |
| 99 | + Expect(err).NotTo(HaveOccurred()) |
| 100 | + |
| 101 | + beforePrimaryIndex := cluster.Status.CurrentPrimaryIndex |
| 102 | + |
| 103 | + go func() { |
| 104 | + // Calling SLEEP within an UPDATE statement creates a situation where a global read lock is intentionally acquired. |
| 105 | + // The value specified for SLEEP must be more than half the value of `PreStopSeconds`. |
| 106 | + runInPod("mysql", "-u", "user", "-pabc", |
| 107 | + "-h", "moco-test-primary.switchover.svc.cluster.local", "test", |
| 108 | + "-e", "UPDATE test.t1 SET foo = SLEEP(15)") |
| 109 | + }() |
| 110 | + |
| 111 | + kubectlSafe(nil, "moco", "-n", "switchover", "switchover", "test") |
| 112 | + Eventually(func() int { |
| 113 | + cluster, err := getCluster("switchover", "test") |
| 114 | + if err != nil { |
| 115 | + return 0 |
| 116 | + } |
| 117 | + return cluster.Status.CurrentPrimaryIndex |
| 118 | + }).ShouldNot(Equal(beforePrimaryIndex)) |
| 119 | + |
| 120 | + Eventually(func() error { |
| 121 | + cluster, err := getCluster("switchover", "test") |
| 122 | + if err != nil { |
| 123 | + return err |
| 124 | + } |
| 125 | + for _, cond := range cluster.Status.Conditions { |
| 126 | + if cond.Type != mocov1beta2.ConditionHealthy { |
| 127 | + continue |
| 128 | + } |
| 129 | + if cond.Status == metav1.ConditionTrue { |
| 130 | + return nil |
| 131 | + } |
| 132 | + return fmt.Errorf("cluster is not healthy: %s", cond.Status) |
| 133 | + } |
| 134 | + return errors.New("no health condition") |
| 135 | + }).Should(Succeed()) |
| 136 | + }) |
| 137 | + |
98 | 138 | It("should delete clusters", func() { |
99 | 139 | kubectlSafe(nil, "delete", "-n", "switchover", "mysqlclusters", "--all") |
100 | 140 | verifyAllPodsDeleted("switchover") |
|
0 commit comments