Repository navigation
test(workloadmanager): add error-path tests for handleDeleteSandbox - #506
SoumaCloud wants to merge 1 commit into
Conversation
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>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
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:
DetailsInstructions 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. |
Problem
handleDeleteSandboxhad 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
The
IsNotFoundcase 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.goAdds
deleteTestStore— a struct that embedsfakeStoreand adds:getSandbox *types.SandboxInfo— controls whatGetSandboxBySessionIDreturns (nil →ErrNotFound)deleteErr error— injected error returned byDeleteSandboxBySessionIDdeleteSessionCalls int— counter to assert how many times store delete was invokedUses
gomonkey.ApplyFuncto replace the package-leveldeleteSandboxfunction at runtime, controlling the K8s response independently of the store:nil→ K8s delete succeededapierrors.NewInternalError(fmt.Errorf("etcd timeout"))→ non-IsNotFound failureapierrors.NewNotFound(schema.GroupResource{Resource: "sandboxes"}, "sandbox-1")→ already deletedThree new tests:
TestHandleDeleteSandbox_K8sDeleteSucceeds_StoreDeleteFails_Returns500TestHandleDeleteSandbox_K8sNonNotFoundError_Returns500TestHandleDeleteSandbox_K8sIsNotFound_IdempotentReturns200All existing tests continue to pass.
How to verify
go test ./pkg/workloadmanager/... -run TestHandleDeleteSandbox -vExpected:
Fixes #500