Skip to content

test(workloadmanager): add error-path tests for handleDeleteSandbox - #506

Open
SoumaCloud wants to merge 1 commit into
volcano-sh:mainfrom
SoumaCloud:test/500-delete-sandbox-error-paths
Open

SoumaCloud wants to merge 1 commit into
volcano-sh:mainfrom
SoumaCloud:test/500-delete-sandbox-error-paths

Conversation

@SoumaCloud

@SoumaCloud SoumaCloud commented Nov 5, 2026 •

Copy link
Copy Markdown

Problem

handleDeleteSandbox had no tests for the three paths where something goes wrong during deletion. Only the happy path (sandbox found, K8s delete succeeds, store delete succeeds) was exercised. A regression silently changing an error response from HTTP 500 to HTTP 200 would not be caught.

Three failure scenarios now covered

Scenario Expected status Store delete called?
K8s delete succeeds, store delete fails 500 Yes (1×)
K8s returns a non-IsNotFound error (e.g. etcd timeout) 500 No — handler bails before reaching the store
K8s returns IsNotFound (resource already deleted) 200 — idempotent success Yes (1×) — store record must still be cleaned up

The IsNotFound case is specifically important: a 404 from Kubernetes means the resource is already gone, which is a valid end state (idempotent delete). The handler must treat this as success, not an error, while still removing the stale store record.

Changes

pkg/workloadmanager/handlers_test.go

  • Adds deleteTestStore — a struct that embeds fakeStore and adds:

    • getSandbox *types.SandboxInfo — controls what GetSandboxBySessionID returns (nil → ErrNotFound)
    • deleteErr error — injected error returned by DeleteSandboxBySessionID
    • deleteSessionCalls int — counter to assert how many times store delete was invoked
  • Uses gomonkey.ApplyFunc to replace the package-level deleteSandbox function at runtime, controlling the K8s response independently of the store:

    • nil → K8s delete succeeded
    • apierrors.NewInternalError(fmt.Errorf("etcd timeout")) → non-IsNotFound failure
    • apierrors.NewNotFound(schema.GroupResource{Resource: "sandboxes"}, "sandbox-1") → already deleted
  • Three new tests:

    • TestHandleDeleteSandbox_K8sDeleteSucceeds_StoreDeleteFails_Returns500
    • TestHandleDeleteSandbox_K8sNonNotFoundError_Returns500
    • TestHandleDeleteSandbox_K8sIsNotFound_IdempotentReturns200

All existing tests continue to pass.

How to verify

go test ./pkg/workloadmanager/... -run TestHandleDeleteSandbox -v

Expected:

--- PASS: TestHandleDeleteSandbox_K8sDeleteSucceeds_StoreDeleteFails_Returns500
--- PASS: TestHandleDeleteSandbox_K8sNonNotFoundError_Returns500
--- PASS: TestHandleDeleteSandbox_K8sIsNotFound_IdempotentReturns200

Fixes #500

handleDeleteSandbox had no test coverage for three important failure modes:

1. K8s delete succeeds but store delete fails → should return 500
2. K8s returns a non-IsNotFound error → should return 500
3. K8s returns IsNotFound → idempotent; should return 200 and still clean the
   store entry

Add TestHandleDeleteSandbox_K8sDeleteSucceeds_StoreDeleteFails_Returns500,
TestHandleDeleteSandbox_K8sNonNotFoundError_Returns500, and
TestHandleDeleteSandbox_K8sIsNotFound_IdempotentReturns200. Each test uses a
deleteTestStore that extends fakeStore with a configurable GetSandboxBySessionID
and DeleteSandboxBySessionID, plus gomonkey patches for the K8s delete functions.

Fixes volcano-sh#500

Signed-off-by: Soumadip <Soum23dip@gmail.com>
@volcano-sh-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign yaozengzeng for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.77%. Comparing base (f521ae9) to head (3d8089e).
⚠️ Report is 25 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #506      +/-   ##
==========================================
+ Coverage   60.45%   62.77%   +2.32%     
==========================================
  Files          35       35              
  Lines        3616     3659      +43     
==========================================
+ Hits         2186     2297     +111     
+ Misses       1211     1138      -73     
- Partials      219      224       +5     
Flag Coverage Δ
unittests 62.77% <ø> (+2.32%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@volcano-sh-bot

Copy link
Copy Markdown
Contributor

Keywords which can automatically close issues and at(@) or hashtag(#) mentions are not allowed in commit messages.

The list of commits with invalid commit messages:

  • 3d8089e test(workloadmanager): add error-path tests for handleDeleteSandbox
Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add error-path tests for handleDeleteSandbox to verify Kubernetes and store consistency

3 participants