@@ -16,8 +16,12 @@ package ticdc
1616
1717import (
1818 "context"
19+ "time"
1920
2021 "github.com/onsi/ginkgo/v2"
22+ "github.com/pingcap/tidb-operator/pkg/client"
23+ "github.com/pingcap/tidb-operator/tests/e2e/utils/waiter"
24+ "k8s.io/utils/ptr"
2125
2226 "github.com/pingcap/tidb-operator/api/v2/core/v1alpha1"
2327 "github.com/pingcap/tidb-operator/pkg/apicall"
@@ -29,12 +33,14 @@ import (
2933 "github.com/pingcap/tidb-operator/tests/e2e/utils/cert"
3034)
3135
36+ const (
37+ changedConfig = `log-level = 'warn'`
38+ )
39+
3240var _ = ginkgo .Describe ("TiCDC" , label .TiCDC , func () {
3341 f := framework .New ()
3442 f .Setup ()
3543
36- // NOTE(liubo02): this case is failed in e2e env because of the cgroup v2.
37- // Enable it if env is fixed.
3844 ginkgo .DescribeTableSubtree ("Leader Eviction" , label .P1 ,
3945 func (enableTLS bool ) {
4046 if enableTLS {
@@ -92,4 +98,66 @@ var _ = ginkgo.Describe("TiCDC", label.TiCDC, func() {
9298 ginkgo .Entry (nil , false ),
9399 ginkgo .Entry (nil , label .FeatureTLS , true ),
94100 )
101+
102+ ginkgo .Context ("Scale and Update" , label .P0 , func () {
103+ ginkgo .It ("support scale out/in TiCDC" , label .Scale , func (ctx context.Context ) {
104+ pdg := f .MustCreatePD (ctx )
105+ kvg := f .MustCreateTiKV (ctx )
106+ dbg := f .MustCreateTiDB (ctx )
107+ cdcg := f .MustCreateTiCDC (ctx )
108+
109+ ginkgo .By ("Wait for Cluster Ready" )
110+ f .WaitForPDGroupReady (ctx , pdg )
111+ f .WaitForTiKVGroupReady (ctx , kvg )
112+ f .WaitForTiDBGroupReady (ctx , dbg )
113+ f .WaitForTiCDCGroupReady (ctx , cdcg )
114+
115+ ginkgo .By ("Change replica of the TiCDCGroup to 4" )
116+ patch := client .MergeFrom (cdcg .DeepCopy ())
117+ cdcg .Spec .Replicas = ptr.To [int32 ](4 )
118+ f .Must (f .Client .Patch (ctx , cdcg , patch ))
119+ f .WaitForTiCDCGroupReady (ctx , cdcg )
120+
121+ ginkgo .By ("Change replica of the TiCDCGroup to 2" )
122+ patch = client .MergeFrom (cdcg .DeepCopy ())
123+ cdcg .Spec .Replicas = ptr.To [int32 ](2 )
124+ f .Must (f .Client .Patch (ctx , cdcg , patch ))
125+ f .WaitForTiCDCGroupReady (ctx , cdcg )
126+ })
127+
128+ ginkgo .It ("support scale TiCDC from 3 to 2 and rolling update at same time" , label .Scale , label .Update , func (ctx context.Context ) {
129+ pdg := f .MustCreatePD (ctx )
130+ kvg := f .MustCreateTiKV (ctx )
131+ dbg := f .MustCreateTiDB (ctx )
132+ cdcg := f .MustCreateTiCDC (ctx , data.WithReplicas [* runtime.TiCDCGroup ](3 ))
133+
134+ f .WaitForPDGroupReady (ctx , pdg )
135+ f .WaitForTiKVGroupReady (ctx , kvg )
136+ f .WaitForTiDBGroupReady (ctx , dbg )
137+ f .WaitForTiCDCGroupReady (ctx , cdcg )
138+
139+ patch := client .MergeFrom (cdcg .DeepCopy ())
140+ cdcg .Spec .Replicas = ptr.To [int32 ](2 )
141+ cdcg .Spec .Template .Spec .Config = changedConfig
142+
143+ nctx , cancel := context .WithCancel (ctx )
144+ ch := make (chan struct {})
145+ go func () {
146+ defer close (ch )
147+ defer ginkgo .GinkgoRecover ()
148+ f .Must (waiter .WaitPodsRollingUpdateOnce (nctx , f .Client , runtime .FromTiCDCGroup (cdcg ), 3 , 1 , waiter .LongTaskTimeout ))
149+ }()
150+
151+ maxTime , err := waiter .MaxPodsCreateTimestamp (ctx , f .Client , runtime .FromTiCDCGroup (cdcg ))
152+ f .Must (err )
153+ changeTime := maxTime .Add (time .Second )
154+
155+ ginkgo .By ("Change config and replicas of the TiCDCGroup" )
156+ f .Must (f .Client .Patch (ctx , cdcg , patch ))
157+ f .Must (waiter .WaitForPodsRecreated (ctx , f .Client , runtime .FromTiCDCGroup (cdcg ), changeTime , waiter .LongTaskTimeout ))
158+ f .WaitForTiCDCGroupReady (ctx , cdcg )
159+ cancel ()
160+ <- ch
161+ })
162+ })
95163})
0 commit comments