Skip to content

Commit 70ac6d0

Browse files
committed
add test for when the timeout is exceeded
1 parent 742a083 commit 70ac6d0

1 file changed

Lines changed: 41 additions & 1 deletion

File tree

e2e/switchover_test.go

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
_ "embed"
55
"errors"
66
"fmt"
7-
87
mocov1beta2 "github.com/cybozu-go/moco/api/v1beta2"
98
. "github.com/onsi/ginkgo/v2"
109
. "github.com/onsi/gomega"
@@ -95,6 +94,47 @@ var _ = Context("switchover", Ordered, func() {
9594
}).Should(Succeed())
9695
})
9796

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+
98138
It("should delete clusters", func() {
99139
kubectlSafe(nil, "delete", "-n", "switchover", "mysqlclusters", "--all")
100140
verifyAllPodsDeleted("switchover")

0 commit comments

Comments
 (0)