testutil

package
v1.1.0-beta.0...-09d12f0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSubTask

func CreateSubTask(t *testing.T, gm *storage.TaskManager, taskID int64, step proto.Step, execID string, meta []byte, tp proto.TaskType, concurrency int) int64

CreateSubTask adds a new task to subtask table. used for testing.

func DeleteSubtasksByTaskID

func DeleteSubtasksByTaskID(ctx context.Context, mgr *storage.TaskManager, taskID int64) error

DeleteSubtasksByTaskID deletes the subtask of the given task ID.

func GetCommonCleanUpRoutine

func GetCommonCleanUpRoutine(ctrl *gomock.Controller) scheduler.CleanUpRoutine

GetCommonCleanUpRoutine returns a common cleanup routine.

func GetCommonStepExecutor

func GetCommonStepExecutor(ctrl *gomock.Controller, runSubtaskFn func(ctx context.Context, subtask *proto.Subtask) error) *mockexecute.MockStepExecutor

GetCommonStepExecutor returns one mock subtaskExecutor.

func GetCommonTaskExecutorExt

func GetCommonTaskExecutorExt(ctrl *gomock.Controller, stepExec *mockexecute.MockStepExecutor) *mock.MockExtension

GetCommonTaskExecutorExt returns a common task executor extension.

func GetMockBasicSchedulerExt

func GetMockBasicSchedulerExt(ctrl *gomock.Controller) scheduler.Extension

GetMockBasicSchedulerExt returns mock scheduler.Extension with basic functionalities.

func GetMockHATestSchedulerExt

func GetMockHATestSchedulerExt(ctrl *gomock.Controller) scheduler.Extension

GetMockHATestSchedulerExt returns mock scheduler.Extension for HA testing with multiple steps.

func GetMockRollbackSchedulerExt

func GetMockRollbackSchedulerExt(ctrl *gomock.Controller) scheduler.Extension

GetMockRollbackSchedulerExt returns mock scheduler.Extension which will generate rollback subtasks.

func GetMockSchedulerExt

func GetMockSchedulerExt(ctrl *gomock.Controller, schedulerInfo SchedulerInfo) scheduler.Extension

GetMockSchedulerExt returns mock scheduler.Extension with input stepInfos. the returned scheduler.Extension will go from StepInit -> each step in stepInfos -> StepDone.

func GetOneTask

func GetOneTask(ctx context.Context, mgr *storage.TaskManager) (task *proto.Task, err error)

GetOneTask get a task from task table

func GetPlanErrSchedulerExt

func GetPlanErrSchedulerExt(ctrl *gomock.Controller, testContext *TestContext) scheduler.Extension

GetPlanErrSchedulerExt returns mock scheduler.Extension which will generate error when planning.

func GetPlanNotRetryableErrSchedulerExt

func GetPlanNotRetryableErrSchedulerExt(ctrl *gomock.Controller) scheduler.Extension

GetPlanNotRetryableErrSchedulerExt returns mock scheduler.Extension which will generate non retryable error when planning.

func GetStepTwoPlanNotRetryableErrSchedulerExt

func GetStepTwoPlanNotRetryableErrSchedulerExt(ctrl *gomock.Controller) scheduler.Extension

GetStepTwoPlanNotRetryableErrSchedulerExt returns mock scheduler.Extension which will generate non retryable error when planning for step two.

func GetSubtaskEndTime

func GetSubtaskEndTime(ctx context.Context, mgr *storage.TaskManager, subtaskID int64) (time.Time, error)

GetSubtaskEndTime gets subtask's endTime for test.

func GetSubtaskNodes

func GetSubtaskNodes(ctx context.Context, mgr *storage.TaskManager, taskID int64) ([]string, error)

GetSubtaskNodes gets nodes that are running or have run the task for test.

func GetSubtasksByTaskID

func GetSubtasksByTaskID(ctx context.Context, mgr *storage.TaskManager, taskID int64) ([]*proto.Subtask, error)

GetSubtasksByTaskID gets subtasks by taskID for test.

func GetSubtasksFromHistory

func GetSubtasksFromHistory(ctx context.Context, mgr *storage.TaskManager) (int, error)

GetSubtasksFromHistory gets subtasks from history table for test.

func GetSubtasksFromHistoryByTaskID

func GetSubtasksFromHistoryByTaskID(ctx context.Context, mgr *storage.TaskManager, taskID int64) (int, error)

GetSubtasksFromHistoryByTaskID gets subtasks by taskID from history table for test.

func GetTaskEndTime

func GetTaskEndTime(ctx context.Context, mgr *storage.TaskManager, taskID int64) (time.Time, error)

GetTaskEndTime gets task's endTime for test.

func GetTasksFromHistory

func GetTasksFromHistory(ctx context.Context, mgr *storage.TaskManager) (int, error)

GetTasksFromHistory gets tasks from history table for test.

func GetTasksFromHistoryInStates

func GetTasksFromHistoryInStates(ctx context.Context, mgr *storage.TaskManager, states ...any) (task []*proto.Task, err error)

GetTasksFromHistoryInStates gets the tasks in history table in the states.

func InitTableTest

func InitTableTest(t *testing.T) (kv.Storage, *storage.TaskManager, context.Context)

InitTableTest inits needed components for table_test. it disables disttask and mock cpu count to 8.

func InitTableTestWithCancel

func InitTableTestWithCancel(t *testing.T) (*storage.TaskManager, context.Context, context.CancelFunc)

InitTableTestWithCancel inits needed components with context.CancelFunc for table_test.

func InitTaskExecutor

func InitTaskExecutor(ctrl *gomock.Controller, runSubtaskFn func(ctx context.Context, subtask *proto.Subtask) error)

InitTaskExecutor inits all mock components for TaskExecutor.

func InsertSubtask

func InsertSubtask(t *testing.T, gm *storage.TaskManager, taskID int64, step proto.Step, execID string, meta []byte, state proto.SubtaskState, tp proto.TaskType, concurrency int) int64

InsertSubtask adds a new subtask of any state to subtask table.

func IsTaskCancelling

func IsTaskCancelling(ctx context.Context, mgr *storage.TaskManager, taskID int64) (bool, error)

IsTaskCancelling checks whether the task state is cancelling.

func PrintSubtaskInfo

func PrintSubtaskInfo(ctx context.Context, mgr *storage.TaskManager, taskID int64)

PrintSubtaskInfo log the subtask info by taskKey for test.

func ReduceCheckInterval

func ReduceCheckInterval(t testing.TB)

ReduceCheckInterval reduces the check interval for test.

func RegisterExampleTask

func RegisterExampleTask(
	t testing.TB,
	schedulerExt scheduler.Extension,
	executorExt taskexecutor.Extension,
	mockCleanup scheduler.CleanUpRoutine,
)

RegisterExampleTask register example task.

func RegisterTaskTypeForRollback

func RegisterTaskTypeForRollback(t testing.TB, ctrl *gomock.Controller, schedulerExt scheduler.Extension, testContext *TestContext)

RegisterTaskTypeForRollback register rollback task meta.

func SubmitAndWaitTask

func SubmitAndWaitTask(ctx context.Context, t testing.TB, taskKey string, targetScope string, concurrency int) *proto.TaskBase

SubmitAndWaitTask schedule one task.

func TransferSubTasks2History

func TransferSubTasks2History(ctx context.Context, mgr *storage.TaskManager, taskID int64) error

TransferSubTasks2History move subtasks from tidb_background_subtask to tidb_background_subtask_history.

func UpdateSubtaskExecID

func UpdateSubtaskExecID(ctx context.Context, mgr *storage.TaskManager, tidbID string, subtaskID int64) error

UpdateSubtaskExecID updates the subtask's exec_id, used for testing now.

func WaitTaskDone

func WaitTaskDone(ctx context.Context, t testing.TB, taskKey string) *proto.TaskBase

WaitTaskDone wait task done.

func WaitTaskDoneOrPaused

func WaitTaskDoneOrPaused(ctx context.Context, t testing.TB, taskKey string) *proto.TaskBase

WaitTaskDoneOrPaused wait task done or paused.

Types

type SchedulerInfo

type SchedulerInfo struct {
	AllErrorRetryable bool
	StepInfos         []StepInfo
}

SchedulerInfo is used for mocking scheduler.Extension.

type StepInfo

type StepInfo struct {
	Step proto.Step

	Err            error
	ErrRepeatCount int64
	SubtaskCnt     int
	// contains filtered or unexported fields
}

StepInfo is used for mocking scheduler.Extension.

type TestContext

type TestContext struct {
	sync.RWMutex

	// for plan err handling tests.
	CallTime int
	// contains filtered or unexported fields
}

TestContext defines shared variables for disttask tests.

func (*TestContext) CollectSubtask

func (c *TestContext) CollectSubtask(subtask *proto.Subtask)

CollectSubtask collects subtask info

func (*TestContext) CollectedSubtaskCnt

func (c *TestContext) CollectedSubtaskCnt(taskID int64, step proto.Step) int

CollectedSubtaskCnt returns the collected subtask count.

type TestDXFContext

type TestDXFContext struct {
	T           testing.TB
	Store       kv.Storage
	Ctx         context.Context
	TaskMgr     *storage.TaskManager
	MockCtrl    *gomock.Controller
	TestContext *TestContext
	Rand        *rand.Rand
	// contains filtered or unexported fields
}

TestDXFContext is the context for testing DXF.

func NewDXFContextWithRandomNodes

func NewDXFContextWithRandomNodes(t testing.TB, minCnt, maxCnt int) *TestDXFContext

NewDXFContextWithRandomNodes creates a new TestDXFContext with random number of nodes in range [minCnt, maxCnt].

func NewTestDXFContext

func NewTestDXFContext(t testing.TB, nodeNum int, cpuCount int, reduceCheckInterval bool) *TestDXFContext

NewTestDXFContext creates a new TestDXFContext.

func (*TestDXFContext) AsyncChangeOwner

func (c *TestDXFContext) AsyncChangeOwner()

AsyncChangeOwner resigns all current owners and changes the owner of the cluster to random node asynchronously.

func (*TestDXFContext) AsyncShutdown

func (c *TestDXFContext) AsyncShutdown(id string)

AsyncShutdown shutdown node asynchronously.

func (*TestDXFContext) ChangeOwner

func (c *TestDXFContext) ChangeOwner()

ChangeOwner resigns all current owners and changes the owner of the cluster to random node.

func (*TestDXFContext) GetNodeIDByIdx

func (c *TestDXFContext) GetNodeIDByIdx(idx int) string

GetNodeIDByIdx returns nodeID by idx in nodes.

func (*TestDXFContext) GetRandNodeIDs

func (c *TestDXFContext) GetRandNodeIDs(limit int) map[string]struct{}

GetRandNodeIDs returns `limit` random node ids. if limit > len(nodes), return all nodes.

func (*TestDXFContext) NodeCount

func (c *TestDXFContext) NodeCount() int

NodeCount returns the number of nodes.

func (*TestDXFContext) ScaleIn

func (c *TestDXFContext) ScaleIn(nodeNum int)

ScaleIn scales in some last added tidb nodes, elect new owner if required.

func (*TestDXFContext) ScaleInBy

func (c *TestDXFContext) ScaleInBy(id string)

ScaleInBy scales in a tidb node by id, elect new owner if required.

func (*TestDXFContext) ScaleOut

func (c *TestDXFContext) ScaleOut(nodeNum int)

ScaleOut scales out a tidb node, and elect owner if required.

func (*TestDXFContext) ScaleOutBy

func (c *TestDXFContext) ScaleOutBy(id string, owner bool)

ScaleOutBy scales out a tidb node by id, and set it as owner if required.

func (*TestDXFContext) WaitAsyncOperations

func (c *TestDXFContext) WaitAsyncOperations()

WaitAsyncOperations waits all async operations to finish.

Jump to

Keyboard shortcuts

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