MCPcopy
hub / github.com/pingcap/tidb / runTestInSchemaState

Function runTestInSchemaState

pkg/server/internal/testserverclient/server_client.go:2997–3094  ·  view source on GitHub ↗
(
	t *testing.T,
	conn *sql.Conn,
	cli *TestServerClient,
	state model.SchemaState,
	isOnJobUpdated bool,
	dropColumnSQL string,
	sqlWithErrs []sqlWithErr,
	expectQuery *expectQuery,
)

Source from the content-addressed store, hash-verified

2995}
2996
2997func runTestInSchemaState(
2998 t *testing.T,
2999 conn *sql.Conn,
3000 cli *TestServerClient,
3001 state model.SchemaState,
3002 isOnJobUpdated bool,
3003 dropColumnSQL string,
3004 sqlWithErrs []sqlWithErr,
3005 expectQuery *expectQuery,
3006) {
3007 ctx := context.Background()
3008 MustExec(ctx, t, conn, "use test_db_state")
3009
3010 prevState := model.StateNone
3011 var checkErr error
3012 dbt := cli.getNewDB(t, func(config *mysql.Config) {
3013 config.MaxAllowedPacket = 1024
3014 })
3015 conn1, err := dbt.GetDB().Conn(ctx)
3016 require.NoError(t, err)
3017 defer func() {
3018 err := dbt.GetDB().Close()
3019 require.NoError(t, err)
3020 }()
3021 MustExec(ctx, t, conn1, "use test_db_state")
3022
3023 for i, sqlWithErr := range sqlWithErrs {
3024 // Start the test txn.
3025 // Step 1: begin(when i = 0).
3026 if i == 0 || i == len(sqlWithErrs)-1 {
3027 sqlWithErr := sqlWithErrs[i]
3028 MustExec(ctx, t, conn1, sqlWithErr.sql)
3029 } else {
3030 // Step 2: prepare stmts.
3031 // SELECT a, c, d from stock where (a, b) IN ((?, ?),(?, ?)) FOR UPDATE
3032 // UPDATE stock SET c = ? WHERE a= ? AND b = 'a'
3033 // UPDATE stock SET c = ?, d = 'z' WHERE a= ? AND b = 'b'
3034 stmt, err := conn1.PrepareContext(ctx, sqlWithErr.sql)
3035 require.NoError(t, err)
3036 sqlWithErr.stmt = stmt
3037 sqlWithErrs[i] = sqlWithErr
3038 }
3039 }
3040
3041 // Step 3: begin.
3042 sqlWithErr := sqlWithErrs[0]
3043 MustExec(ctx, t, conn1, sqlWithErr.sql)
3044
3045 prevState = model.StateNone
3046 state = model.StateWriteOnly
3047 cbFunc1 := func(job *model.Job) {
3048 if jobStateOrLastSubJobState(job) == prevState || checkErr != nil {
3049 return
3050 }
3051 prevState = jobStateOrLastSubJobState(job)
3052 if prevState != state {
3053 return
3054 }

Callers 2

RunTestIssue53634Method · 0.70
RunTestIssue54254Method · 0.70

Calls 11

EnableCallFunction · 0.92
DisableFunction · 0.92
MustQueryFunction · 0.85
getNewDBMethod · 0.80
GetDBMethod · 0.80
CheckRowsMethod · 0.80
MustExecFunction · 0.70
CloseMethod · 0.65
ExecContextMethod · 0.65
QueryContextMethod · 0.65

Tested by

no test coverage detected