github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/tests/integration_tests/cdc/dailytest/exector.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 dailytest
    15  
    16  import (
    17  	"database/sql"
    18  	"fmt"
    19  	"sync"
    20  
    21  	"github.com/pingcap/log"
    22  )
    23  
    24  // RunDailyTest generates insert/update/delete sqls and execute
    25  func RunDailyTest(db *sql.DB, tableSQLs []string, workerCount int, jobCount int, batch int) {
    26  	var wg sync.WaitGroup
    27  	wg.Add(len(tableSQLs))
    28  
    29  	for i := range tableSQLs {
    30  		go func(i int) {
    31  			defer wg.Done()
    32  
    33  			table := newTable()
    34  			err := parseTableSQL(table, tableSQLs[i])
    35  			if err != nil {
    36  				log.S().Fatal(err)
    37  			}
    38  
    39  			err = execSQL(db, tableSQLs[i])
    40  			if err != nil {
    41  				log.S().Fatal(err)
    42  			}
    43  
    44  			doProcess(table, db, jobCount, workerCount, batch)
    45  		}(i)
    46  	}
    47  
    48  	wg.Wait()
    49  }
    50  
    51  // TruncateTestTable truncates test data
    52  func TruncateTestTable(db *sql.DB, tableSQLs []string) {
    53  	for i := range tableSQLs {
    54  		table := newTable()
    55  		err := parseTableSQL(table, tableSQLs[i])
    56  		if err != nil {
    57  			log.S().Fatal(err)
    58  		}
    59  
    60  		err = execSQL(db, fmt.Sprintf("truncate table %s", table.name))
    61  		if err != nil {
    62  			log.S().Fatal(err)
    63  		}
    64  	}
    65  }
    66  
    67  // DropTestTable drops test table
    68  func DropTestTable(db *sql.DB, tableSQLs []string) {
    69  	for i := range tableSQLs {
    70  		table := newTable()
    71  		err := parseTableSQL(table, tableSQLs[i])
    72  		if err != nil {
    73  			log.S().Fatal(err)
    74  		}
    75  
    76  		err = execSQL(db, fmt.Sprintf("drop table %s", table.name))
    77  		if err != nil {
    78  			log.S().Fatal(err)
    79  		}
    80  	}
    81  }