agentfield icon indicating copy to clipboard operation
agentfield copied to clipboard

[Control Plane] Add unit tests for execution cleanup handler

Open santoshkumarradha opened this issue 11 months ago • 17 comments

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.

santoshkumarradha avatar Dec 23 '25 16:12 santoshkumarradha

Hey! I want to do this task

1khazipov avatar Feb 25 '26 20:02 1khazipov

Thanks for picking this up, @1khazipov! :tada:

Here's what to expect:

  • We'll check in after 7 days if we haven't heard an update
  • After 14 days, we'll send a second reminder
  • After 21 days without activity, we'll unassign to let others contribute

Tips for success:

  • Drop a comment when you start working on it
  • Share any blockers - we're here to help!
  • Link your PR with Fixes #118 in the description

Happy coding! :rocket:

github-actions[bot] avatar Feb 26 '26 07:02 github-actions[bot]

Hey @1khazipov , I noticed you’re working on another one as well. Maybe we can focus on completing one before taking on the next, just to keep things streamlined.

santoshkumarradha avatar Feb 26 '26 07:02 santoshkumarradha

@santoshkumarradha PRs on other issues are already done

1khazipov avatar Feb 26 '26 07:02 1khazipov

Thanks for picking this up, @1khazipov! :tada:

Here's what to expect:

  • We'll check in after 7 days if we haven't heard an update
  • After 14 days, we'll send a second reminder
  • After 21 days without activity, we'll unassign to let others contribute

Tips for success:

  • Drop a comment when you start working on it
  • Share any blockers - we're here to help!
  • Link your PR with Fixes #118 in the description

Happy coding! :rocket:

github-actions[bot] avatar Feb 26 '26 16:02 github-actions[bot]

oops my bad

@santoshkumarradha PRs on other issues are already done

santoshkumarradha avatar Feb 26 '26 16:02 santoshkumarradha

Hey @1khazipov! :wave:

Just a friendly reminder that you're assigned to this issue. It's been about a week since assignment.

How's it going? We'd love to hear:

  • Any progress updates?
  • Running into any blockers we can help with?
  • Need more time? (Totally fine!)

A quick comment helps us know you're still interested. If your plans have changed, no worries at all - just let us know and we can find another contributor.

Thanks for contributing to AgentField! :rocket:

github-actions[bot] avatar Mar 05 '26 09:03 github-actions[bot]

Hi @1khazipov,

Just checking in again! It's been 14 days since we last heard from you on this issue.

Quick options:

  • :speech_balloon: Drop a comment with a progress update
  • :link: Link a draft PR if you've started working on it
  • :wave: Let us know if you'd like to be unassigned (no judgment!)

If we don't hear back in 7 days, we'll unassign this issue to give other contributors a chance to help.

Thanks for understanding!

github-actions[bot] avatar Mar 12 '26 09:03 github-actions[bot]

Hi @1khazipov,

It's been 21 days since the last update on this issue. To keep the project moving, we've unassigned this issue so other contributors can pick it up.

No worries at all! Life happens, and we totally understand. If you'd like to continue working on this, just comment here and we'll reassign it to you.

This issue is now available for anyone who'd like to contribute. Check out our contribution guidelines if you're interested!

Thanks for your interest in AgentField! :heart:

github-actions[bot] avatar Mar 19 '26 09:03 github-actions[bot]

Hi @santoshkumarradha, I would like to pick this up if it is still open.

Plan: table-driven tests in control-plane/internal/handlers/execution_cleanup_test.go against a stub StorageProvider, following the embedded-interface pattern already used in coverage_additional_test.go so only the four methods the service actually calls need overriding (CleanupOldExecutions, MarkStaleExecutions, MarkStaleWorkflowExecutions, RetryStaleWorkflowExecutions).

Coverage target is the five areas listed in the issue: stale execution detection, batch processing, context cancellation, error handling, and metrics tracking. I will also cover ForceCleanup and the disabled-config path through Start.

No new dependencies, testify is already in go.mod.

0xHerm avatar Aug 07 '26 21:08 0xHerm

Thanks for picking this up, @0xHerm! :tada:

Here's what to expect:

  • We'll check in after 7 days if we haven't heard an update
  • After 14 days, we'll send a second reminder
  • After 21 days without activity, we'll unassign to let others contribute

Tips for success:

  • Drop a comment when you start working on it
  • Share any blockers - we're here to help!
  • Link your PR with Fixes #118 in the description

Happy coding! :rocket:

github-actions[bot] avatar Aug 07 '26 21:08 github-actions[bot]

Thanks @0xHerm, all yours! 🚀

santoshkumarradha avatar Aug 07 '26 21:08 santoshkumarradha

Withdrawing my earlier note above, and flagging that this issue looks already satisfied.

control-plane/internal/handlers/execution_cleanup_test.go already exists (639 lines, 12 test functions), added in #195 test(control-plane): add execution cleanup service coverage, with further cases in coverage_low_branches_test.go. The "Test coverage: None" line in the description is stale.

All five areas listed in the issue are covered today. Measured on main with go test ./internal/handlers/ -coverprofile:

Function Coverage
NewExecutionCleanupService 100%
Start 100%
Stop 100%
GetMetrics 100%
ForceCleanup 100%
performCleanup 97.9%
cleanupLoop 84.6%

Stale detection, batch processing, context cancellation, error handling and metrics tracking all have dedicated tests, so I do not think there is anything left to do here. Suggest closing.

The only uncovered branches were the two timer cases in cleanupLoop and the RetryStaleWorkflowExecutions error path. The initial-cleanup branch was unreachable because the delay is hardcoded at 30s. I have opened a separate PR for that specific gap rather than reopening scope here.

0xHerm avatar Aug 08 '26 00:08 0xHerm

Hey @0xHerm! :wave:

Just a friendly reminder that you're assigned to this issue. It's been about a week since assignment.

How's it going? We'd love to hear:

  • Any progress updates?
  • Running into any blockers we can help with?
  • Need more time? (Totally fine!)

A quick comment helps us know you're still interested. If your plans have changed, no worries at all - just let us know and we can find another contributor.

Thanks for contributing to AgentField! :rocket:

github-actions[bot] avatar Aug 15 '26 09:08 github-actions[bot]

Status update (responding to the reminder): no work remaining here. This issue is fully satisfied on main.

Every item in the acceptance criteria maps to an existing test: stale detection and the no-stale/all-stale edge cases (TestExecutionCleanupService_PerformCleanup_CleansStaleExecutionsInBatches, ..._NoStaleExecutions, ..._AllExecutionsStale), batch processing (same batch test), context cancellation (..._StopsWhenContextIsCancelled, ...CleanupLoop_StopsOnContextCancellation), error handling (..._StoresErrorWhenCleanupFails plus the three continue-on-error tests), and metrics (..._AccumulatesMetricsAcrossRuns). The bulk landed in #195, and #897 (merged Aug 10) covered the last unreachable branches, so execution_cleanup.go now sits at 100% coverage across all seven functions, per the coverage table in that PR.

@santoshkumarradha I believe this can be closed as completed.

0xHerm avatar Aug 15 '26 11:08 0xHerm

Hey @0xHerm! :wave:

Just a friendly reminder that you're assigned to this issue. It's been about a week since assignment.

How's it going? We'd love to hear:

  • Any progress updates?
  • Running into any blockers we can help with?
  • Need more time? (Totally fine!)

A quick comment helps us know you're still interested. If your plans have changed, no worries at all - just let us know and we can find another contributor.

Thanks for contributing to AgentField! :rocket:

github-actions[bot] avatar Aug 23 '26 09:08 github-actions[bot]

Verified, @0xHerm — you're right, and you undersold it slightly.

go test ./internal/handlers/ -run 'ExecutionCleanup' -count=1 -coverprofile=... then go tool cover -func gives 100.0% on every function in execution_cleanup.go: NewExecutionCleanupService, Start, Stop, GetMetrics, cleanupLoop, performCleanup, ForceCleanup. 18 tests pass, not 12 — the extra six come from execution_cleanup_loop_test.go. I walked each acceptance bullet to a test name and they all land: batching and stale detection in ..._CleansStaleExecutionsInBatches, both cancellation paths, four continue-on-error tests, and ..._AccumulatesMetricsAcrossRuns for metrics.

Closing as completed. Thanks for the #897 follow-up too — making the initial delay injectable is what got cleanupLoop to 100% instead of leaving a dead branch.

AbirAbbas avatar Aug 26 '26 14:08 AbirAbbas