testkit

package
v1.1.0-beta.0...-de36787 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 61 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WithTiKV = flag.String("with-tikv", "", "address of tikv cluster, if set, running test with real tikv cluster")

WithTiKV flag is only used for debugging locally with real tikv cluster.

Functions

func CreateMockStore

func CreateMockStore(t testing.TB, opts ...mockstore.MockTiKVStoreOption) kv.Storage

CreateMockStore return a new mock kv.Storage.

func CreateMockStoreAndDomain

func CreateMockStoreAndDomain(t testing.TB, opts ...mockstore.MockTiKVStoreOption) (kv.Storage, *domain.Domain)

CreateMockStoreAndDomain return a new mock kv.Storage and *domain.Domain.

func CreateMockStoreAndDomainWithSchemaLease

func CreateMockStoreAndDomainWithSchemaLease(t testing.TB, lease time.Duration, opts ...mockstore.MockTiKVStoreOption) (kv.Storage, *domain.Domain)

CreateMockStoreAndDomainWithSchemaLease return a new mock kv.Storage and *domain.Domain.

func CreateMockStoreWithSchemaLease

func CreateMockStoreWithSchemaLease(t testing.TB, lease time.Duration, opts ...mockstore.MockTiKVStoreOption) kv.Storage

CreateMockStoreWithSchemaLease return a new mock kv.Storage.

func GetStack

func GetStack() []byte

GetStack gets the stacktrace.

func MockTiDBStatusPort

func MockTiDBStatusPort(ctx context.Context, b *testing.B, port string) *util.WaitGroupWrapper

MockTiDBStatusPort mock the TiDB server status port to have metrics.

func NewSession

func NewSession(t testing.TB, store kv.Storage) sessiontypes.Session

NewSession creates a new session environment for test.

func Rows

func Rows(args ...string) [][]any

Rows is similar to RowsWithSep, use white space as separator string.

func RowsWithSep

func RowsWithSep(sep string, args ...string) [][]any

RowsWithSep is a convenient function to wrap args to a slice of []interface. The arg represents a row, split by sep.

func SetTiFlashReplica

func SetTiFlashReplica(t testing.TB, dom *domain.Domain, dbName, tableName string)

SetTiFlashReplica is to set TiFlash replica

func TryRetrieveSession

func TryRetrieveSession(ctx context.Context) sessiontypes.Session

TryRetrieveSession tries retrieve session from context.

func WithPruneMode

func WithPruneMode(tk *TestKit, mode variable.PartitionPruneMode, f func())

WithPruneMode run test case under prune mode.

Types

type AsyncTestKit

type AsyncTestKit struct {
	// contains filtered or unexported fields
}

AsyncTestKit is a utility to run sql concurrently.

func NewAsyncTestKit

func NewAsyncTestKit(t *testing.T, store kv.Storage) *AsyncTestKit

NewAsyncTestKit returns a new *AsyncTestKit.

func (*AsyncTestKit) CloseSession

func (tk *AsyncTestKit) CloseSession(ctx context.Context)

CloseSession closes exists session from ctx.

func (*AsyncTestKit) ConcurrentRun

func (tk *AsyncTestKit) ConcurrentRun(
	concurrent int,
	loops int,
	prepareFunc func(ctx context.Context, tk *AsyncTestKit, concurrent int, currentLoop int) [][][]any,
	writeFunc func(ctx context.Context, tk *AsyncTestKit, input [][]any),
	checkFunc func(ctx context.Context, tk *AsyncTestKit),
)

ConcurrentRun run test in current. - concurrent: controls the concurrent worker count. - loops: controls run test how much times. - prepareFunc: provide test data and will be called for every loop. - checkFunc: used to do some check after all workers done. works like create table better be put in front of this method calling. see more example at TestBatchInsertWithOnDuplicate

func (*AsyncTestKit) Exec

func (tk *AsyncTestKit) Exec(ctx context.Context, sql string, args ...any) (sqlexec.RecordSet, error)

Exec executes a sql statement.

func (*AsyncTestKit) ExecToErr

func (tk *AsyncTestKit) ExecToErr(ctx context.Context, sql string, args ...any) error

ExecToErr executes a sql statement and discard results.

func (*AsyncTestKit) MustExec

func (tk *AsyncTestKit) MustExec(ctx context.Context, sql string, args ...any)

MustExec executes a sql statement and asserts nil error.

func (*AsyncTestKit) MustGetErrMsg

func (tk *AsyncTestKit) MustGetErrMsg(ctx context.Context, sql string, errStr string)

MustGetErrMsg executes a sql statement and assert its error message.

func (*AsyncTestKit) MustQuery

func (tk *AsyncTestKit) MustQuery(ctx context.Context, sql string, args ...any) *Result

MustQuery query the statements and returns result rows. If expected result is set it asserts the query result equals expected result.

func (*AsyncTestKit) OpenSession

func (tk *AsyncTestKit) OpenSession(ctx context.Context, db string) context.Context

OpenSession opens new session ctx if no exists one and use db.

type DBTestKit

type DBTestKit struct {
	// contains filtered or unexported fields
}

DBTestKit is a utility to run sql with a db connection.

func NewDBTestKit

func NewDBTestKit(t *testing.T, db *sql.DB) *DBTestKit

NewDBTestKit returns a new *DBTestKit.

func (*DBTestKit) GetDB

func (tk *DBTestKit) GetDB() *sql.DB

GetDB returns the underlay sql.DB instance.

func (*DBTestKit) MustExec

func (tk *DBTestKit) MustExec(sql string, args ...any) sql.Result

MustExec query the statements and returns the result.

func (*DBTestKit) MustExecPrepared

func (tk *DBTestKit) MustExecPrepared(stmt *sql.Stmt, args ...any) sql.Result

MustExecPrepared executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.

func (*DBTestKit) MustPrepare

func (tk *DBTestKit) MustPrepare(query string) *sql.Stmt

MustPrepare creates a prepared statement for later queries or executions.

func (*DBTestKit) MustQuery

func (tk *DBTestKit) MustQuery(sql string, args ...any) *sql.Rows

MustQuery query the statements and returns result rows.

func (*DBTestKit) MustQueryPrepared

func (tk *DBTestKit) MustQueryPrepared(stmt *sql.Stmt, args ...any) *sql.Rows

MustQueryPrepared executes a prepared query statement with the given arguments and returns the query results as a *Rows.

func (*DBTestKit) MustQueryRows

func (tk *DBTestKit) MustQueryRows(query string, args ...any)

MustQueryRows query the statements

type DistExecutionContext

type DistExecutionContext struct {
	Store kv.Storage
	// contains filtered or unexported fields
}

DistExecutionContext is the context that used in Distributed execution test for Dist task framework and DDL. TODO remove it after we can start multiple DDL job scheduler separately.

func NewDistExecutionContext

func NewDistExecutionContext(t testing.TB, serverNum int) *DistExecutionContext

NewDistExecutionContext create DistExecutionContext for testing.

func NewDistExecutionContextWithLease

func NewDistExecutionContextWithLease(t testing.TB, serverNum int, lease time.Duration) *DistExecutionContext

NewDistExecutionContextWithLease create DistExecutionContext for testing.

func (*DistExecutionContext) Close

func (d *DistExecutionContext) Close()

Close cleanup running goroutines, release resources used.

func (*DistExecutionContext) GetDomain

func (d *DistExecutionContext) GetDomain(idx int) *domain.Domain

GetDomain get domain by index.

func (*DistExecutionContext) TriggerOwnerChange

func (d *DistExecutionContext) TriggerOwnerChange()

TriggerOwnerChange set one mock domain to DDL Owner by idx.

type MockSessionManager

type MockSessionManager struct {
	PS      []*util.ProcessInfo
	PSMu    sync.RWMutex
	SerID   uint64
	TxnInfo []*txninfo.TxnInfo
	Dom     *domain.Domain
	Conn    map[uint64]sessiontypes.Session

	ConAttrs map[uint64]map[string]string
	// contains filtered or unexported fields
}

MockSessionManager is a mocked session manager which is used for test.

func (*MockSessionManager) CheckOldRunningTxn

func (msm *MockSessionManager) CheckOldRunningTxn(job2ver map[int64]int64, job2ids map[int64]string)

CheckOldRunningTxn is to get all startTS of every transactions running in the current internal sessions

func (*MockSessionManager) DeleteInternalSession

func (msm *MockSessionManager) DeleteInternalSession(s any)

DeleteInternalSession is to delete the internal session pointer from the map in the SessionManager

func (*MockSessionManager) GetConAttrs

func (msm *MockSessionManager) GetConAttrs(user *auth.UserIdentity) map[uint64]map[string]string

GetConAttrs returns the connection attributes of all connections

func (*MockSessionManager) GetInternalSessionStartTSList

func (msm *MockSessionManager) GetInternalSessionStartTSList() []uint64

GetInternalSessionStartTSList is to get all startTS of every transaction running in the current internal sessions

func (*MockSessionManager) GetProcessInfo

func (msm *MockSessionManager) GetProcessInfo(id uint64) (*util.ProcessInfo, bool)

GetProcessInfo implements the SessionManager.GetProcessInfo interface.

func (*MockSessionManager) Kill

Kill implements the SessionManager.Kill interface.

func (*MockSessionManager) KillAllConnections

func (*MockSessionManager) KillAllConnections()

KillAllConnections implements the SessionManager.KillAllConnections interface.

func (*MockSessionManager) KillNonFlashbackClusterConn

func (msm *MockSessionManager) KillNonFlashbackClusterConn()

KillNonFlashbackClusterConn implement SessionManager interface.

func (*MockSessionManager) ServerID

func (msm *MockSessionManager) ServerID() uint64

ServerID get server id.

func (*MockSessionManager) ShowProcessList

func (msm *MockSessionManager) ShowProcessList() map[uint64]*util.ProcessInfo

ShowProcessList implements the SessionManager.ShowProcessList interface.

func (*MockSessionManager) ShowTxnList

func (msm *MockSessionManager) ShowTxnList() []*txninfo.TxnInfo

ShowTxnList is to show txn list.

func (*MockSessionManager) StoreInternalSession

func (msm *MockSessionManager) StoreInternalSession(s any)

StoreInternalSession is to store internal session.

func (*MockSessionManager) UpdateTLSConfig

func (*MockSessionManager) UpdateTLSConfig(*tls.Config)

UpdateTLSConfig implements the SessionManager.UpdateTLSConfig interface.

type RegionProperityClient

type RegionProperityClient struct {
	tikv.Client
	// contains filtered or unexported fields
}

RegionProperityClient is to get region properties.

func (*RegionProperityClient) SendRequest

func (c *RegionProperityClient) SendRequest(ctx context.Context, addr string, req *tikvrpc.Request, timeout time.Duration) (*tikvrpc.Response, error)

SendRequest is to mock send request.

type Result

type Result struct {
	// contains filtered or unexported fields
}

Result is the result returned by MustQuery.

func (*Result) AddComment

func (res *Result) AddComment(c string)

AddComment adds the extra comment for the Result's output.

func (*Result) Check

func (res *Result) Check(expected [][]any)

Check asserts the result equals the expected results.

func (*Result) CheckAt

func (res *Result) CheckAt(cols []int, expected [][]any)

CheckAt asserts the result of selected columns equals the expected results.

func (*Result) CheckContain

func (res *Result) CheckContain(expected string)

CheckContain checks whether the result contains the expected string

func (*Result) CheckNotContain

func (res *Result) CheckNotContain(unexpected string)

CheckNotContain checks whether the result doesn't contain the expected string

func (*Result) CheckWithFunc

func (res *Result) CheckWithFunc(expected [][]any, f func([]string, []any) bool)

CheckWithFunc asserts the result match the expected results in the way `f` specifies.

func (*Result) Equal

func (res *Result) Equal(expected [][]any) bool

Equal check whether the result equals the expected results.

func (*Result) MultiCheckContain

func (res *Result) MultiCheckContain(expecteds []string)

MultiCheckContain checks whether the result contains strings in `expecteds`

func (*Result) MultiCheckNotContain

func (res *Result) MultiCheckNotContain(unexpecteds []string)

MultiCheckNotContain checks whether the result doesn't contain the strings in `expected`

func (*Result) Rows

func (res *Result) Rows() [][]any

Rows returns the result data.

func (*Result) Sort

func (res *Result) Sort() *Result

Sort sorts and return the result.

func (*Result) String

func (res *Result) String() string

type SteppedTestKit

type SteppedTestKit struct {
	// contains filtered or unexported fields
}

SteppedTestKit is the testkit that can run stepped command

func NewSteppedTestKit

func NewSteppedTestKit(t testing.TB, store kv.Storage) *SteppedTestKit

NewSteppedTestKit creates a new SteppedTestKit

func (*SteppedTestKit) Continue

func (tk *SteppedTestKit) Continue() *SteppedTestKit

Continue continues current command

func (*SteppedTestKit) ExpectIdle

func (tk *SteppedTestKit) ExpectIdle()

ExpectIdle checks no command is running

func (*SteppedTestKit) ExpectStopOnAnyBreakPoint

func (tk *SteppedTestKit) ExpectStopOnAnyBreakPoint()

ExpectStopOnAnyBreakPoint checks stopped on any break point

func (*SteppedTestKit) ExpectStopOnBreakPoint

func (tk *SteppedTestKit) ExpectStopOnBreakPoint(breakPoint string)

ExpectStopOnBreakPoint checks stopped on the specified break point

func (*SteppedTestKit) GetQueryResult

func (tk *SteppedTestKit) GetQueryResult() *Result

GetQueryResult returns the query result of the latest command

func (*SteppedTestKit) GetResult

func (tk *SteppedTestKit) GetResult() any

GetResult returns the result of the latest command

func (*SteppedTestKit) MustExec

func (tk *SteppedTestKit) MustExec(sql string, args ...any)

MustExec executes a sql statement and asserts nil error.

func (*SteppedTestKit) MustQuery

func (tk *SteppedTestKit) MustQuery(sql string, args ...any) *Result

MustQuery query the statements and returns result rows. If expected result is set it asserts the query result equals expected result.

func (*SteppedTestKit) SetBreakPoints

func (tk *SteppedTestKit) SetBreakPoints(breakPoints ...string)

SetBreakPoints sets the break points we want to stop at

func (*SteppedTestKit) SteppedMustExec

func (tk *SteppedTestKit) SteppedMustExec(sql string, args ...any) *SteppedTestKit

SteppedMustExec creates a new stepped task for MustExec

func (*SteppedTestKit) SteppedMustQuery

func (tk *SteppedTestKit) SteppedMustQuery(sql string, args ...any) *SteppedTestKit

SteppedMustQuery creates a new stepped task for MustQuery

type TestKit

type TestKit struct {
	// contains filtered or unexported fields
}

TestKit is a utility to run sql test.

func NewTestKit

func NewTestKit(t testing.TB, store kv.Storage) *TestKit

NewTestKit returns a new *TestKit.

func NewTestKitWithSession

func NewTestKitWithSession(t testing.TB, store kv.Storage, se sessiontypes.Session) *TestKit

NewTestKitWithSession returns a new *TestKit.

func (*TestKit) CheckExecResult

func (tk *TestKit) CheckExecResult(affectedRows, insertID int64)

CheckExecResult checks the affected rows and the insert id after executing MustExec.

func (*TestKit) CheckLastMessage

func (tk *TestKit) CheckLastMessage(msg string)

CheckLastMessage checks last message after executing MustExec

func (*TestKit) EventuallyMustIndexLookup

func (tk *TestKit) EventuallyMustIndexLookup(sql string, args ...any) *Result

EventuallyMustIndexLookup checks whether the plan for the sql is IndexLookUp.

func (*TestKit) EventuallyMustQueryAndCheck

func (tk *TestKit) EventuallyMustQueryAndCheck(sql string, args []any,
	expected [][]any, waitFor time.Duration, tick time.Duration)

EventuallyMustQueryAndCheck query the statements and assert that result rows.lt will equal the expected results in waitFor time, periodically checking equality each tick. Note: retry can't ignore error of the statements. If statements returns error, it will break out.

func (*TestKit) Exec

func (tk *TestKit) Exec(sql string, args ...any) (sqlexec.RecordSet, error)

Exec executes a sql statement using the prepared stmt API

func (*TestKit) ExecToErr

func (tk *TestKit) ExecToErr(sql string, args ...any) error

ExecToErr executes a sql statement and discard results.

func (*TestKit) ExecWithContext

func (tk *TestKit) ExecWithContext(ctx context.Context, sql string, args ...any) (rs sqlexec.RecordSet, err error)

ExecWithContext executes a sql statement using the prepared stmt API

func (*TestKit) HasKeywordInOperatorInfo

func (tk *TestKit) HasKeywordInOperatorInfo(sql string, keyword string, args ...any) bool

HasKeywordInOperatorInfo checks if the result execution plan contains specific keyword in the operator info.

func (*TestKit) HasPlanForLastExecution

func (tk *TestKit) HasPlanForLastExecution(plan string) bool

HasPlanForLastExecution checks if the execution plan of the last execution contains specific plan.

func (*TestKit) HasTiFlashPlan

func (tk *TestKit) HasTiFlashPlan(sql string, args ...any) bool

HasTiFlashPlan checks if the result execution plan contains TiFlash plan.

func (*TestKit) MustContainErrMsg

func (tk *TestKit) MustContainErrMsg(sql string, errStr any)

MustContainErrMsg executes a sql statement and assert its error message containing errStr.

func (*TestKit) MustExec

func (tk *TestKit) MustExec(sql string, args ...any)

MustExec executes a sql statement and asserts nil error.

func (*TestKit) MustExecToErr

func (tk *TestKit) MustExecToErr(sql string, args ...any)

MustExecToErr executes a sql statement and must return Error.

func (*TestKit) MustExecWithContext

func (tk *TestKit) MustExecWithContext(ctx context.Context, sql string, args ...any)

MustExecWithContext executes a sql statement and asserts nil error.

func (*TestKit) MustGetDBError

func (tk *TestKit) MustGetDBError(sql string, dberr *terror.Error)

MustGetDBError executes a sql statement and assert its terror.

func (*TestKit) MustGetErrCode

func (tk *TestKit) MustGetErrCode(sql string, errCode int)

MustGetErrCode executes a sql statement and assert it's error code.

func (*TestKit) MustGetErrMsg

func (tk *TestKit) MustGetErrMsg(sql string, errStr string)

MustGetErrMsg executes a sql statement and assert its error message.

func (*TestKit) MustHavePlan

func (tk *TestKit) MustHavePlan(sql string, plan string, args ...any)

MustHavePlan checks if the result execution plan contains specific plan.

func (*TestKit) MustIndexLookup

func (tk *TestKit) MustIndexLookup(sql string, args ...any) *Result

MustIndexLookup checks whether the plan for the sql is IndexLookUp.

func (*TestKit) MustMatchErrMsg

func (tk *TestKit) MustMatchErrMsg(sql string, errRx any)

MustMatchErrMsg executes a sql statement and assert its error message matching errRx.

func (*TestKit) MustNoGlobalStats

func (tk *TestKit) MustNoGlobalStats(table string)

MustNoGlobalStats checks if there is no global stats.

func (*TestKit) MustNoIndexUsed

func (tk *TestKit) MustNoIndexUsed(sql string, args ...any)

MustNoIndexUsed checks if the result execution plan contains no index.

func (*TestKit) MustNotHavePlan

func (tk *TestKit) MustNotHavePlan(sql string, plan string, args ...any)

MustNotHavePlan checks if the result execution plan contains specific plan.

func (*TestKit) MustPartition

func (tk *TestKit) MustPartition(sql string, partitions string, args ...any) *Result

MustPartition checks if the result execution plan must read specific partitions.

func (*TestKit) MustPartitionByList

func (tk *TestKit) MustPartitionByList(sql string, partitions []string, args ...any) *Result

MustPartitionByList checks if the result execution plan must read specific partitions by list.

func (*TestKit) MustPointGet

func (tk *TestKit) MustPointGet(sql string, args ...any) *Result

MustPointGet checks whether the plan for the sql is Point_Get.

func (*TestKit) MustQuery

func (tk *TestKit) MustQuery(sql string, args ...any) *Result

MustQuery query the statements and returns result rows. If expected result is set it asserts the query result equals expected result.

func (*TestKit) MustQueryToErr

func (tk *TestKit) MustQueryToErr(sql string, args ...any)

MustQueryToErr query the sql statement and must return Error.

func (*TestKit) MustQueryWithContext

func (tk *TestKit) MustQueryWithContext(ctx context.Context, sql string, args ...any) *Result

MustQueryWithContext query the statements and returns result rows.

func (*TestKit) MustUseIndex

func (tk *TestKit) MustUseIndex(sql string, index string, args ...any)

MustUseIndex checks if the result execution plan contains specific index(es).

func (*TestKit) MustUseIndexForConnection

func (tk *TestKit) MustUseIndexForConnection(connID string, index string)

MustUseIndexForConnection checks if the result execution plan contains specific index(es) for a connection.

func (*TestKit) NotHasKeywordInOperatorInfo

func (tk *TestKit) NotHasKeywordInOperatorInfo(sql string, keyword string, args ...any) bool

NotHasKeywordInOperatorInfo checks if the result execution plan doesn't contain specific keyword in the operator info.

func (*TestKit) QueryToErr

func (tk *TestKit) QueryToErr(sql string, args ...any) error

QueryToErr executes a sql statement and discard results.

func (*TestKit) RefreshConnectionID

func (tk *TestKit) RefreshConnectionID()

RefreshConnectionID refresh the connection ID for session of the testkit

func (*TestKit) RefreshSession

func (tk *TestKit) RefreshSession()

RefreshSession set a new session for the testkit

func (*TestKit) RequireEqual

func (tk *TestKit) RequireEqual(expected any, actual any, msgAndArgs ...any)

RequireEqual checks if actual is equal to the expected

func (*TestKit) RequireNoError

func (tk *TestKit) RequireNoError(err error, msgAndArgs ...any)

RequireNoError checks if error happens

func (*TestKit) RequireNotEqual

func (tk *TestKit) RequireNotEqual(expected any, actual any, msgAndArgs ...any)

RequireNotEqual checks if actual is not equal to the expected

func (*TestKit) ResultSetToResult

func (tk *TestKit) ResultSetToResult(rs sqlexec.RecordSet, comment string) *Result

ResultSetToResult converts sqlexec.RecordSet to testkit.Result. It is used to check results of execute statement in binary mode.

func (*TestKit) ResultSetToResultWithCtx

func (tk *TestKit) ResultSetToResultWithCtx(ctx context.Context, rs sqlexec.RecordSet, comment string) *Result

ResultSetToResultWithCtx converts sqlexec.RecordSet to testkit.Result.

func (*TestKit) Session

func (tk *TestKit) Session() sessiontypes.Session

Session return the session associated with the testkit

func (*TestKit) SetSession

func (tk *TestKit) SetSession(session sessiontypes.Session)

SetSession set the session of testkit

func (*TestKit) UsedPartitions

func (tk *TestKit) UsedPartitions(sql string, args ...any) *Result

UsedPartitions returns the partition names that will be used or all/dual.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL