Documentation
¶
Index ¶
- func AssertInlineRescheduledRunParams(t *testing.T, server Server, dagName, dagRunID string)
- func CreateInlineDAGRunForReschedule(t *testing.T, server Server, dagName string, enqueue bool) (string, string)
- func CreateStaleLegacyProcFile(t *testing.T, procDir string, groupName string, dagRun exec.DAGRunRef, ...) string
- func CreateStaleLegacyProcFileWithAttempt(t *testing.T, procDir string, groupName string, dagRun exec.DAGRunRef, ...) string
- func EnvOutput(names ...string) string
- func EnvOutputWithSeparator(separator string, names ...string) string
- func ExpandedOutput(ref string) string
- func ExpectedInlineTempPath(name, dagRunID string) string
- func ForOS(posix, windows string) string
- func JoinLines(lines ...string) string
- func JoinShellCommands(commands ...string) string
- func LabeledExpandedOutput(prefix, ref string) string
- func Output(value string) string
- func OutputEscaped(value string) string
- func PosixQuote(value string) string
- func PowerShellQuote(value string) string
- func ProcessQueuedInlineRun(t *testing.T, server Server, queueName string)
- func ReadRunStatus(ctx context.Context, t *testing.T, store exec.DAGRunStore, ...) *exec.DAGRunStatus
- func ReadTestdata(t *testing.T, filename string) []byte
- func RequireProcHeartbeatAdvance(t *testing.T, ctx context.Context, procStore ProcHeartbeatObserver, ...)
- func ReserveServerListener(t *testing.T) (net.Listener, string)
- func RunBuiltCLI(t *testing.T, th Helper, extraEnv []string, args ...string) string
- func RunBuiltCLICommand(tb testing.TB, th Helper, extraEnv []string, args ...string) ([]byte, error)
- func ShellPath(path string) string
- func ShellQuote(value string) string
- func Sleep(d time.Duration) string
- func StatusOutputValue(t *testing.T, status *coreexec.DAGRunStatus, key string) string
- func Stderr(value string) string
- func SubprocessRunTimeout(base time.Duration) time.Duration
- func TestdataPath(t *testing.T, filename string) string
- func WaitForAttemptSnapshot(t *testing.T, server Server, dagName, dagRunID string) exec.DAGRunAttempt
- func WaitForAttemptSnapshotWithDAG(t *testing.T, server Server, dagName, dagRunID string) (exec.DAGRunAttempt, *core.DAG)
- func WaitForProcHeartbeat(t *testing.T, ctx context.Context, procStore ProcHeartbeatObserver, ...) exec.ProcHeartbeat
- func WithConfigFlag(args []string, cfg *config.Config) []string
- type APIClient
- type Agent
- type AgentOption
- type CmdTest
- type Command
- func (c Command) CreateDAGFile(t *testing.T, name string, content string) string
- func (th Command) ExecuteCommand(cmd *cobra.Command, testCase CmdTest) error
- func (th Command) RunCommand(t *testing.T, cmd *cobra.Command, testCase CmdTest)
- func (th Command) RunCommandWithError(t *testing.T, cmd *cobra.Command, testCase CmdTest) error
- type Contains
- type Coordinator
- func (c *Coordinator) Address() string
- func (c *Coordinator) DispatchTask(t *testing.T, task *coordinatorv1.Task) error
- func (c *Coordinator) GetCoordinatorClient(t *testing.T) coordinator.Client
- func (c *Coordinator) Handler() *coordinator.Handler
- func (c *Coordinator) LogDir() string
- func (c *Coordinator) Port() int
- func (c *Coordinator) Stop() error
- type DAG
- func (d *DAG) Agent(opts ...AgentOption) *Agent
- func (d *DAG) AssertCurrentStatus(t *testing.T, expected core.Status)
- func (d *DAG) AssertDAGRunCount(t *testing.T, expected int)
- func (d *DAG) AssertLatestStatus(t *testing.T, expected core.Status)
- func (d *DAG) AssertOutputs(t *testing.T, outputs map[string]any)
- func (d *DAG) ReadOutputs(t *testing.T) map[string]string
- type Helper
- func (h Helper) Cleanup()
- func (h Helper) CreateDAGFile(t *testing.T, dir string, name string, yamlContent []byte) string
- func (h Helper) DAG(t *testing.T, yamlContent string) DAG
- func (h Helper) DAGExpectError(t *testing.T, name string, expectedErr string)
- func (h Helper) TempFile(t *testing.T, name string, data []byte) string
- type HelperOption
- func WithArtifactPersistence() HelperOption
- func WithBuiltExecutable() HelperOption
- func WithCaptureLoggingOutput() HelperOption
- func WithConfigMutator(mutator func(*config.Config)) HelperOption
- func WithCoordinatorConfig(host string, port int) HelperOption
- func WithCoordinatorEnabled() HelperOption
- func WithDAGsDir(dir string) HelperOption
- func WithLogPersistence() HelperOption
- func WithSchedulerTestDAGs(dagsDir string) HelperOption
- func WithServerConfig(cfg *config.Server) HelperOption
- func WithServerOptions(serverOpts ...frontend.ServerOption) HelperOption
- func WithStaleThresholds(heartbeat, lease time.Duration) HelperOption
- func WithStatusPersistence() HelperOption
- type NotEmpty
- type Options
- type ProcHeartbeatObserver
- type Request
- type Response
- type Scheduler
- type Server
- type SyncBuffer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateStaleLegacyProcFile ¶
func CreateStaleLegacyProcFile( t *testing.T, procDir string, groupName string, dagRun exec.DAGRunRef, startedAt time.Time, age time.Duration, ) string
CreateStaleLegacyProcFile writes a stale legacy .proc heartbeat file for the given dag-run.
func CreateStaleLegacyProcFileWithAttempt ¶
func CreateStaleLegacyProcFileWithAttempt( t *testing.T, procDir string, groupName string, dagRun exec.DAGRunRef, attemptID string, startedAt time.Time, age time.Duration, ) string
CreateStaleLegacyProcFileWithAttempt writes a stale legacy .proc heartbeat file for the given dag-run and attempt.
func EnvOutputWithSeparator ¶
func ExpandedOutput ¶
ExpandedOutput emits a Dagu-resolved ${...} value while keeping shell quoting valid on each platform. The input should be a Dagu reference, not an arbitrary literal string.
func ExpectedInlineTempPath ¶
func JoinShellCommands ¶
func LabeledExpandedOutput ¶
func OutputEscaped ¶
func PosixQuote ¶
func PowerShellQuote ¶
func ProcessQueuedInlineRun ¶
func ReadRunStatus ¶
func ReadRunStatus(ctx context.Context, t *testing.T, store exec.DAGRunStore, dagRun exec.DAGRunRef) *exec.DAGRunStatus
ReadRunStatus loads the persisted status for the given dag-run reference.
func ReadTestdata ¶
ReadTestdata reads the content of a testdata file.
func RequireProcHeartbeatAdvance ¶
func RequireProcHeartbeatAdvance( t *testing.T, ctx context.Context, procStore ProcHeartbeatObserver, groupName string, dagRun exec.DAGRunRef, timeout time.Duration, )
RequireProcHeartbeatAdvance verifies dagRun's proc heartbeat updates within the timeout.
func ReserveServerListener ¶
ReserveServerListener binds a loopback listener and closes it during test cleanup.
func RunBuiltCLI ¶
func RunBuiltCLICommand ¶
func ShellQuote ¶
func StatusOutputValue ¶
func SubprocessRunTimeout ¶
SubprocessRunTimeout returns a timeout appropriate for waiting on the result of a subprocess-executed DAG run. On Windows, process creation is significantly slower so a larger multiplier is used.
func TestdataPath ¶
TestdataPath returns the path to a testdata file.
func WaitForAttemptSnapshot ¶
func WaitForProcHeartbeat ¶
func WaitForProcHeartbeat( t *testing.T, ctx context.Context, procStore ProcHeartbeatObserver, groupName string, dagRun exec.DAGRunRef, timeout time.Duration, ) exec.ProcHeartbeat
WaitForProcHeartbeat returns the latest heartbeat observation for dagRun once it exists.
Types ¶
type APIClient ¶
type APIClient struct {
// contains filtered or unexported fields
}
APIClient handles HTTP requests to the test server
type Agent ¶
func (*Agent) RunSuccess ¶
type AgentOption ¶
type AgentOption func(*Agent)
func WithAgentOptions ¶
func WithAgentOptions(options agent.Options) AgentOption
func WithDAGRunID ¶
func WithDAGRunID(dagRunID string) AgentOption
type CmdTest ¶
type CmdTest struct {
Name string // Name of the test.
Args []string // Arguments to pass to the command.
ExpectedOut []string // Expected output to be present in the standard output / error.
}
CmdTest is a helper struct to test commands.
type Command ¶
type Command struct {
Helper
}
Command is a helper struct to test commands.
func SetupCommand ¶
func SetupCommand(t *testing.T, opts ...HelperOption) Command
func (Command) CreateDAGFile ¶
CreateDAGFile creates a DAG file in the DAGsDir for command tests
func (Command) ExecuteCommand ¶
ExecuteCommand runs a command and validates the expected output without touching testing.T. It is safe to use from background goroutines in tests.
func (Command) RunCommand ¶
type Coordinator ¶
type Coordinator struct {
Helper
// contains filtered or unexported fields
}
Coordinator represents a test gRPC coordinator instance
func SetupCoordinator ¶
func SetupCoordinator(t *testing.T, opts ...HelperOption) *Coordinator
SetupCoordinator creates and starts a test coordinator instance
func (*Coordinator) Address ¶
func (c *Coordinator) Address() string
Address returns the address the coordinator is listening on
func (*Coordinator) DispatchTask ¶
func (c *Coordinator) DispatchTask(t *testing.T, task *coordinatorv1.Task) error
DispatchTask dispatches a task to a waiting worker
func (*Coordinator) GetCoordinatorClient ¶
func (c *Coordinator) GetCoordinatorClient(t *testing.T) coordinator.Client
GetCoordinatorClient returns a coordinator client for this coordinator
func (*Coordinator) Handler ¶
func (c *Coordinator) Handler() *coordinator.Handler
Handler returns the coordinator handler for direct testing
func (*Coordinator) LogDir ¶
func (c *Coordinator) LogDir() string
LogDir returns the log directory path for verifying log persistence
func (*Coordinator) Port ¶
func (c *Coordinator) Port() int
Port returns the port the coordinator is listening on
func (*Coordinator) Stop ¶
func (c *Coordinator) Stop() error
Stop gracefully shuts down the coordinator
type DAG ¶
func (*DAG) Agent ¶
func (d *DAG) Agent(opts ...AgentOption) *Agent
func (*DAG) AssertCurrentStatus ¶
func (*DAG) AssertLatestStatus ¶
func (*DAG) AssertOutputs ¶
AssertOutputs checks the given outputs against the actual outputs of the DAG Note that this function does not respect dependencies between nodes making the outputs with the same key indeterministic
type Helper ¶
type Helper struct {
Context context.Context
Cancel context.CancelFunc
Config *config.Config
ChildEnv []string
LoggingOutput *SyncBuffer
DAGStore exec1.DAGStore
DAGRunStore exec1.DAGRunStore
DAGRunMgr runtimepkg.Manager
ProcStore exec1.ProcStore
QueueStore exec1.QueueStore
StateStore dagstate.Store
ServiceRegistry exec1.ServiceRegistry
DispatchTaskStore exec1.DispatchTaskStore
WorkerHeartbeatStore exec1.WorkerHeartbeatStore
DAGRunLeaseStore exec1.DAGRunLeaseStore
ActiveDistributedRunStore exec1.ActiveDistributedRunStore
SubCmdBuilder *launcher.SubCmdBuilder
ServerOptions []frontend.ServerOption
StaleHeartbeatThreshold time.Duration
StaleLeaseThreshold time.Duration
// contains filtered or unexported fields
}
Helper provides test utilities and configuration
func Setup ¶
func Setup(t *testing.T, opts ...HelperOption) Helper
Setup creates and returns a Helper preconfigured for tests.
Setup prepares an isolated test environment: it creates a temporary DAGU_HOME, writes a minimal config file, initializes stores and a runtime manager, sets key environment variables (e.g. DEBUG, CI, TZ, DAGU_EXECUTABLE, DAGU_CONFIG, SHELL), installs a cancellable context, and registers cleanup to restore the working directory and remove the temp directory. Use the returned Helper to interact with the test runtime and stores.
func (Helper) CreateDAGFile ¶
CreateDAGFile creates a DAG file in a given directory for tests that need separate DAG files
func (Helper) DAGExpectError ¶
type HelperOption ¶
type HelperOption func(*Options)
HelperOption defines functional options for Helper
func WithArtifactPersistence ¶
func WithArtifactPersistence() HelperOption
WithArtifactPersistence enables artifact persistence to filesystem on the coordinator handler. Use this for testing remote artifact uploads from workers.
func WithBuiltExecutable ¶
func WithBuiltExecutable() HelperOption
WithBuiltExecutable makes Setup build the current ./cmd binary once and use it as cfg.Paths.Executable for subprocess-based tests.
func WithCaptureLoggingOutput ¶
func WithCaptureLoggingOutput() HelperOption
WithCaptureLoggingOutput creates a logging capture option
func WithConfigMutator ¶
func WithConfigMutator(mutator func(*config.Config)) HelperOption
WithConfigMutator applies mutations to the loaded configuration after defaults are set.
func WithCoordinatorConfig ¶
func WithCoordinatorConfig(host string, port int) HelperOption
WithCoordinatorConfig creates a coordinator configuration option
func WithCoordinatorEnabled ¶
func WithCoordinatorEnabled() HelperOption
WithCoordinatorEnabled re-enables the coordinator in test configuration. By default, tests disable the coordinator since no coordinator is running.
func WithDAGsDir ¶
func WithDAGsDir(dir string) HelperOption
func WithLogPersistence ¶
func WithLogPersistence() HelperOption
WithLogPersistence enables log persistence to filesystem on the coordinator handler. Use this for testing remote log streaming from workers.
func WithSchedulerTestDAGs ¶
func WithSchedulerTestDAGs(dagsDir string) HelperOption
WithSchedulerTestDAGs creates a scheduler option for setting up test DAGs directory
func WithServerConfig ¶
func WithServerConfig(cfg *config.Server) HelperOption
func WithServerOptions ¶
func WithServerOptions(serverOpts ...frontend.ServerOption) HelperOption
WithServerOptions appends frontend.ServerOption values to be passed when creating the test server.
func WithStaleThresholds ¶
func WithStaleThresholds(heartbeat, lease time.Duration) HelperOption
WithStaleThresholds overrides the shared heartbeat and lease staleness thresholds used by distributed test helpers. Useful for tests that need faster zombie detection or dispatch reservation expiry.
func WithStatusPersistence ¶
func WithStatusPersistence() HelperOption
WithStatusPersistence enables status persistence via DAGRunStore on the coordinator handler. Use this for testing remote status pushing from workers.
type Options ¶
type Options struct {
CaptureLoggingOutput bool // CaptureLoggingOutput enables capturing of logging output
DAGsDir string
ServerConfig *config.Server
ConfigMutators []func(*config.Config)
CoordinatorHost string
CoordinatorPort int
ServerOptions []frontend.ServerOption
UseBuiltExecutable bool // UseBuiltExecutable builds the current ./cmd binary for subprocess-based tests
// Coordinator handler options for worker tests
WithStatusPersistence bool // Enable status persistence via DAGRunStore
WithLogPersistence bool // Enable log persistence to filesystem
WithArtifactPersistence bool // Enable artifact persistence to filesystem
StaleHeartbeatThreshold time.Duration // Override for handler's stale heartbeat threshold
StaleLeaseThreshold time.Duration // Override for handler's stale lease threshold
}
type ProcHeartbeatObserver ¶
type ProcHeartbeatObserver interface {
LatestHeartbeat(ctx context.Context, groupName string, dagRun exec.DAGRunRef) (*exec.ProcHeartbeat, error)
}
ProcHeartbeatObserver is the proc-store surface needed by heartbeat liveness tests.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request represents an HTTP request being prepared
func (*Request) ExpectStatus ¶
ExpectStatus sets the expected HTTP status code
func (*Request) WithBasicAuth ¶
WithBasicAuth adds Basic authentication to the request
func (*Request) WithBearerToken ¶
WithBearerToken adds a Bearer token to the Authorization header
func (*Request) WithHeader ¶
WithHeader adds a header to the request
type Scheduler ¶
type Scheduler struct {
Helper
EntryReader scheduler.EntryReader
QueueStore exec.QueueStore
CoordinatorCli exec.Dispatcher
}
Scheduler represents a test scheduler instance
func SetupScheduler ¶
func SetupScheduler(t *testing.T, opts ...HelperOption) *Scheduler
SetupScheduler creates a test scheduler instance with all dependencies
func (*Scheduler) NewSchedulerInstance ¶
NewSchedulerInstance creates a new scheduler instance for testing
type Server ¶
type Server struct {
Helper
}
Server represents a test HTTP server instance
func SetupServer ¶
func SetupServer(t *testing.T, opts ...HelperOption) Server
SetupServer creates and starts a test server instance
type SyncBuffer ¶
type SyncBuffer struct {
// contains filtered or unexported fields
}
SyncBuffer provides thread-safe buffer operations
func (*SyncBuffer) Reset ¶
func (b *SyncBuffer) Reset()
func (*SyncBuffer) String ¶
func (b *SyncBuffer) String() string