Skip to content

[Control Plane] Add unit tests for execution cleanup handler #118

@santoshkumarradha

Description

@santoshkumarradha

Summary

Add unit tests for the execution cleanup background service which removes stale executions.

Current State

  • File: control-plane/internal/handlers/execution_cleanup.go
  • Size: 242 lines
  • Test coverage: None

What to Test

  1. Stale execution detection: Test that executions older than threshold are identified
  2. Batch processing: Test cleanup processes executions in batches
  3. Context cancellation: Test graceful shutdown when context is cancelled
  4. Error handling: Test behavior when storage operations fail
  5. Metrics tracking: Test that cleanup counts are tracked correctly

Implementation Notes

  • Mock the execution store to return controlled test data
  • Test different batch sizes and thresholds
  • Verify logging output for cleanup operations
  • Test edge cases (no stale executions, all stale executions)

Example Test Structure

func TestExecutionCleanup_CleansStaleExecutions(t *testing.T) {
    // Setup mock store with stale executions
    // Run cleanup
    // Verify stale executions were cleaned
}

func TestExecutionCleanup_RespectsContextCancellation(t *testing.T) {
    // Setup mock store
    // Cancel context
    // Verify cleanup stops gracefully
}

Acceptance Criteria

  • Create execution_cleanup_test.go
  • Test coverage for stale detection logic
  • Test coverage for batch processing
  • Test coverage for error handling
  • All tests pass with go test ./internal/handlers/...

Files

  • Source: control-plane/internal/handlers/execution_cleanup.go
  • Test: control-plane/internal/handlers/execution_cleanup_test.go (new)

Using AI to solve this issue? Read our AI-Assisted Contributions guide for testing requirements, prompt strategies, and common pitfalls to avoid.

Metadata

Metadata

Assignees

Labels

area:control-planeControl plane server functionalitygood first issueGood for newcomerstestsUnit test improvements and coverage

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions