Skip to content

test(queue): add coverage for hierarchical queue controller propagation logic#5321

Open
ayuxsh009 wants to merge 1 commit into
volcano-sh:masterfrom
ayuxsh009:test/hierarchical-queue-controller-unit-tests
Open

test(queue): add coverage for hierarchical queue controller propagation logic#5321
ayuxsh009 wants to merge 1 commit into
volcano-sh:masterfrom
ayuxsh009:test/hierarchical-queue-controller-unit-tests

Conversation

@ayuxsh009
Copy link
Copy Markdown

PR Description

What this PR does

Adds unit test coverage for hierarchical queue controller actions in:

  • pkg/controllers/queue/queue_controller_action.go
  • pkg/controllers/queue/queue_controller_handler.go

These paths previously had effectively no direct test coverage.

Why this PR is needed

The hierarchical queue controller logic is responsible for propagating
parent queue state changes to child queues and will be relied upon by the
upcoming NamespaceQueue functionality.

The covered functions include:

  • syncHierarchicalQueue
  • openHierarchicalQueue
  • closeHierarchicalQueue
  • updateQueueParent
  • updateQueueAnnotation
  • updateQueue event handler

Before this PR, the only indirect coverage came from TestSyncQueue,
which used a "root" queue and bypassed most hierarchical logic paths.

Changes made

  • Added addQueueToStore helper to populate informer cache state during tests
    without requiring a running informer.
  • Added 20 new sub-tests across 6 table-driven test suites:
    • TestUpdateQueueParent
    • TestUpdateQueueAnnotation
    • TestUpdateQueueHandler
    • TestSyncHierarchicalQueue
    • TestOpenHierarchicalQueue
    • TestCloseHierarchicalQueue
  • Verified propagation behavior for:
    • parent close/open state transitions
    • child queue reopening
    • annotation updates
    • default parent assignment
    • queue hierarchy synchronization edge cases

Test plan

go test ./pkg/controllers/queue/... -v

What type of PR is this?

/kind test

Which issue(s) this PR fixes

Fixes N/A

Special notes for reviewers

  • No production code changes are included.
  • Tests use the existing newFakeController() pattern and fake clients.
  • Informer cache state is injected directly through the added helper to keep
    tests lightweight and deterministic.

AI disclosure

Claude Code (claude-sonnet-4-6) was used only for initial assistance in identifying uncovered paths and generating a rough test scaffold.

The actual test scenarios, assertions, informer-store setup, edge-case handling, and final implementation were manually reviewed, expanded, modified, and validated locally. Significant manual work was done to refine the test logic, ensure realistic controller behavior coverage, and verify all cases with local test runs before submission.

Does this PR introduce a user-facing change?

NONE

Signed-off-by: ayuxsh009 <1raj.aayush@gmail.com>
Copilot AI review requested due to automatic review settings May 17, 2026 06:48
@volcano-sh-bot
Copy link
Copy Markdown
Contributor

@ayuxsh009: The label(s) kind/test cannot be applied, because the repository doesn't have them.

Details

In response to this:

PR Description

What this PR does

Adds unit test coverage for hierarchical queue controller actions in:

  • pkg/controllers/queue/queue_controller_action.go
  • pkg/controllers/queue/queue_controller_handler.go

These paths previously had effectively no direct test coverage.

Why this PR is needed

The hierarchical queue controller logic is responsible for propagating
parent queue state changes to child queues and will be relied upon by the
upcoming NamespaceQueue functionality.

The covered functions include:

  • syncHierarchicalQueue
  • openHierarchicalQueue
  • closeHierarchicalQueue
  • updateQueueParent
  • updateQueueAnnotation
  • updateQueue event handler

Before this PR, the only indirect coverage came from TestSyncQueue,
which used a "root" queue and bypassed most hierarchical logic paths.

Changes made

  • Added addQueueToStore helper to populate informer cache state during tests
    without requiring a running informer.
  • Added 20 new sub-tests across 6 table-driven test suites:
  • TestUpdateQueueParent
  • TestUpdateQueueAnnotation
  • TestUpdateQueueHandler
  • TestSyncHierarchicalQueue
  • TestOpenHierarchicalQueue
  • TestCloseHierarchicalQueue
  • Verified propagation behavior for:
  • parent close/open state transitions
  • child queue reopening
  • annotation updates
  • default parent assignment
  • queue hierarchy synchronization edge cases

Test plan

go test ./pkg/controllers/queue/... -v

What type of PR is this?

/kind test

Which issue(s) this PR fixes

Fixes N/A

Special notes for reviewers

  • No production code changes are included.
  • Tests use the existing newFakeController() pattern and fake clients.
  • Informer cache state is injected directly through the added helper to keep
    tests lightweight and deterministic.

AI disclosure

Claude Code (claude-sonnet-4-6) was used only for initial assistance in identifying uncovered paths and generating a rough test scaffold.

The actual test scenarios, assertions, informer-store setup, edge-case handling, and final implementation were manually reviewed, expanded, modified, and validated locally. Significant manual work was done to refine the test logic, ensure realistic controller behavior coverage, and verify all cases with local test runs before submission.

Does this PR introduce a user-facing change?

NONE

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.

@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 jessestutler 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

@volcano-sh-bot
Copy link
Copy Markdown
Contributor

Welcome @ayuxsh009! It looks like this is your first PR to volcano-sh/volcano 🎉

@volcano-sh-bot volcano-sh-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 17, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive suite of unit tests for hierarchical queue management within the queue controller, covering parent updates, annotation handling, and state synchronization between parent and child queues. The reviewer provided feedback aimed at improving test robustness, specifically recommending that existing annotations be verified for preservation during updates and that test resource creation be made more consistent to avoid fragility against future implementation changes.

}
result, err := c.updateQueueAnnotation(tc.queue, tc.annotationKey, tc.annotationValue)
assert.NoError(t, err)
assert.Equal(t, tc.expectValue, result.Annotations[tc.annotationKey])
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In the test case existing annotations get new key appended, the assertion only verifies the presence of the new annotation. It is recommended to also verify that existing annotations (e.g., unrelated-key) are preserved to ensure the update logic correctly merges annotations rather than accidentally overwriting the entire map.

Comment on lines +596 to +599
if tc.childInVCClient {
_, err := c.vcClient.SchedulingV1beta1().Queues().Create(context.TODO(), tc.child, metav1.CreateOptions{})
assert.NoError(t, err)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The conditional creation of the child queue in the fake client based on tc.childInVCClient makes the test setup fragile. If the implementation of syncHierarchicalQueue is updated to perform any API interaction (such as logging an event or updating a different field) for cases where childInVCClient is currently false, the test will fail with a 'not found' error. It is more robust to always create the queue in the fake client and assert on the specific actions taken or the final state.

References
  1. Tests should be robust against implementation changes that do not affect the core logic being tested.

Comment on lines +778 to +782
if child.Status.State != schedulingv1beta1.QueueStateClosed &&
child.Status.State != schedulingv1beta1.QueueStateClosing {
_, err := c.vcClient.SchedulingV1beta1().Queues().Create(context.TODO(), child, metav1.CreateOptions{})
assert.NoError(t, err)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to TestSyncHierarchicalQueue, this conditional creation of children in the fake client is fragile. It assumes that closeHierarchicalQueue will only attempt to patch queues that are not already in Closed or Closing states. If the logic changes to ensure consistency (e.g., ensuring the annotation is present even if already closed), this test will fail. Creating all children in the fake client provides a more realistic and robust test environment.

References
  1. Tests should be robust against implementation changes that do not affect the core logic being tested.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds direct unit test coverage for hierarchical queue controller propagation logic, exercising parent/child state transitions and annotation/parent defaulting behaviors in the queue controller.

Changes:

  • Introduces a lightweight helper to inject Queue objects into the informer cache for lister-based code paths.
  • Adds table-driven test suites covering syncHierarchicalQueue, openHierarchicalQueue, closeHierarchicalQueue, updateQueueParent, updateQueueAnnotation, and the updateQueue event handler behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// addQueueToStore adds a Queue to the controller's informer cache so that
// queueLister.Get / queueLister.List return it without needing a running informer.
func addQueueToStore(c *queuecontroller, q *schedulingv1beta1.Queue) {
_ = c.queueInformer.Informer().GetStore().Add(q)
@ayuxsh009
Copy link
Copy Markdown
Author

Hi @kingeasternsun , @wangyang0616 have a look on this

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

Labels

size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants