github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/chaos/cases/cases.go (about) 1 // Copyright 2020 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package main 15 16 import ( 17 "context" 18 "path/filepath" 19 20 "github.com/pingcap/tiflow/dm/config/dbconfig" 21 "github.com/pingcap/tiflow/dm/pb" 22 "github.com/pingcap/tiflow/dm/pkg/utils" 23 "golang.org/x/sync/errgroup" 24 ) 25 26 var ( 27 // NOTE: items in `doSchemas` should be specified in the corresponding task files (`filenames`). 28 // TODO: can not support optimistic shard DDL now because go-sqlsmith will generated some statements like 29 // `ALTER TABLE `db_optimistic`.`dxeyydwb` ADD COLUMN (`zuhxfgsce` INT(18) NOT NULL)` which has NOT NULL column without DEFAULT value. 30 filenames = []string{"task-single.yaml", "task-pessimistic.yaml", "task-optimistic.yaml"} 31 doSchemas = []string{"db_single", "db_pessimistic", "db_optimistic"} 32 ) 33 34 // runCases runs test cases. 35 func runCases(ctx context.Context, cli pb.MasterClient, confDir string, 36 targetCfg dbconfig.DBConfig, sourcesCfg ...dbconfig.DBConfig, 37 ) error { 38 eg, ctx2 := errgroup.WithContext(ctx) 39 for i := range filenames { 40 taskFile := filepath.Join(confDir, filenames[i]) 41 schema := doSchemas[i] 42 eg.Go(func() error { 43 t, err := newTask(ctx2, cli, taskFile, schema, targetCfg, sourcesCfg...) 44 if err != nil { 45 return err 46 } 47 err = t.run() 48 if utils.IsContextCanceledError(err) { 49 err = nil // clear err 50 } 51 return err 52 }) 53 } 54 return eg.Wait() 55 }