Skip to content

test(dataset): migrate dataset controller tests to Ginkgo v2#5683

Draft
hxrshxz wants to merge 3 commits intofluid-cloudnative:masterfrom
hxrshxz:dataset-ginkgo-v2-tests
Draft

test(dataset): migrate dataset controller tests to Ginkgo v2#5683
hxrshxz wants to merge 3 commits intofluid-cloudnative:masterfrom
hxrshxz:dataset-ginkgo-v2-tests

Conversation

@hxrshxz
Copy link
Contributor

@hxrshxz hxrshxz commented Mar 8, 2026

Ⅰ. Describe what this PR does

Migrates pkg/controllers/v1alpha1/dataset tests to Ginkgo v2, adds dataset controller unit coverage, and makes runtime precheck discovery lazy so the dataset package tests do not fail during package initialization.

Ⅱ. Does this pull request fix one issue?

#5676

Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

Added unit tests for:

  • ControllerName
  • addFinalizerAndRequeue success and update error paths
  • reconcileDataset invalid name, finalizer add, phase transition, requeue behavior, deletion delegation, reference dataset validation, thin runtime creation, thin runtime create error, and status update error
  • reconcileDatasetDeletion clean delete, live DatasetRef requeue, stale DatasetRef pruning, PVC/pod deletion blocking, finalizer removal update error, and datasetRef status update error
  • deploy precheck resolution behavior to cover lazy default resolution and injected precheck usage
  • envtest skip gating helper behavior for explicit envtest-start-failure opt-in

Retained the existing envtest-backed dataset creation spec and updated the suite bootstrap to Ginkgo v2 semantics.

Ⅳ. Describe how to verify it

Run:

FLUID_DATASET_TEST_SKIP_ENVTEST_START_FAILURE=true go test -count=1 ./pkg/controllers/v1alpha1/dataset

go test -count=1 ./pkg/controllers/deploy

If you want the envtest-backed dataset spec to run as well, use working envtest assets:

KUBEBUILDER_ASSETS=/home/hxrshxz/.local/share/kubebuilder-envtest/k8s/1.29.4-linux-amd64 go test -v ./pkg/controllers/v1alpha1/dataset/...

Ⅴ. Special notes for reviews

N/A

Copilot AI review requested due to automatic review settings March 8, 2026 05:03
@fluid-e2e-bot
Copy link

fluid-e2e-bot bot commented Mar 8, 2026

[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 yangyuliufeng for approval by writing /assign @yangyuliufeng in a comment. 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

@fluid-e2e-bot
Copy link

fluid-e2e-bot bot commented Mar 8, 2026

Hi @hxrshxz. Thanks for your PR.

I'm waiting for a fluid-cloudnative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the testing infrastructure and robustness of the dataset controller. It upgrades the testing framework to Ginkgo v2, introduces a lazy and thread-safe mechanism for runtime precheck discovery, and substantially expands unit test coverage for core reconciliation and deletion logic, ensuring greater stability and reliability.

Highlights

  • Ginkgo v2 Migration: The dataset controller tests in pkg/controllers/v1alpha1/dataset have been migrated to use Ginkgo v2, updating the testing framework and suite bootstrap.
  • Lazy Runtime Precheck Discovery: Runtime precheck discovery has been refactored to be lazy and thread-safe, preventing test failures during package initialization and improving robustness.
  • Expanded Unit Test Coverage: Extensive new unit tests have been added for the dataset controller, covering ControllerName, finalizer handling, dataset reconciliation logic, deletion processes, and error paths.
Changelog
  • pkg/controllers/deploy/runtime_controllers.go
    • Added sync package import for concurrency primitives.
    • Refactored precheckFuncs initialization from an init() function to a lazy, thread-safe mechanism using sync.Mutex.
    • Introduced getPrecheckFuncs and clonePrecheckFuncs for controlled access and cloning of precheck functions.
    • Updated ScaleoutRuntimeControllerOnDemand to utilize the new getPrecheckFuncs for retrieving runtime checks.
  • pkg/controllers/deploy/runtime_controllers_test.go
    • Added client import for Kubernetes client operations.
    • Implemented restorePrecheckState helper function to manage and restore global precheck state for isolated test execution.
    • Added TestGetPrecheckFuncsResolvesDefaultsLazily to verify the lazy resolution of default precheck functions.
    • Added TestScaleoutRuntimeControllerOnDemandUsesInjectedPrecheckFuncsWithoutResolvingDefaults to confirm that injected precheck functions bypass lazy default resolution.
    • Updated existing TestScaleoutRuntimeContollerOnDemand test cases to correctly handle expected errors and set the common.MyPodNamespace environment variable.
  • pkg/controllers/v1alpha1/dataset/dataset_reconciler_test.go
    • Added a new test file dedicated to unit tests for the DatasetReconciler.
    • Implemented comprehensive unit tests for ControllerName method.
    • Added tests for addFinalizerAndRequeue covering both successful finalizer addition and update error paths.
    • Included extensive tests for reconcileDataset, validating behavior for invalid names, finalizer addition, phase transitions, requeue logic, deletion delegation, reference dataset validation, thin runtime creation (success and error), and status update errors.
    • Developed tests for reconcileDatasetDeletion, covering clean deletion, requeueing due to live DatasetRef entries, pruning of stale DatasetRef entries, blocking by PVCs/pods, and error handling during finalizer removal and datasetRef status updates.
  • pkg/controllers/v1alpha1/dataset/suite_test.go
    • Added strconv package import for string conversions.
    • Introduced testEnvStarted flag and allowSkippingEnvtestStartFailure function to enable conditional skipping of envtest-dependent specs.
    • Migrated the BeforeSuite function to the Ginkgo v2 context signature.
    • Modified BeforeSuite to gracefully handle envtest.Start() errors, allowing tests to proceed if FLUID_DATASET_TEST_SKIP_ENVTEST_START_FAILURE is set.
    • Updated AfterSuite to only attempt stopping the testEnv if it was successfully started.
    • Added a Skip condition to the 'Should create dataset successfully' test if the envtest environment was not started.
  • pkg/controllers/v1alpha1/dataset/suite_test_helpers_test.go
    • Added a new test file containing unit tests for the allowSkippingEnvtestStartFailure helper function.
Activity
  • The pull request was opened by hxrshxz.
  • The author has implemented significant changes to the testing framework and added extensive unit tests for the dataset controller.
  • The author has also refactored runtime precheck discovery to be lazy and thread-safe.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@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 successfully migrates the dataset controller tests to Ginkgo v2, significantly increasing unit test coverage for the dataset reconciler. It also introduces a lazy initialization mechanism for runtime precheck functions to prevent failures during package initialization in tests. My review includes a suggestion to improve the performance of this new lazy loading mechanism by caching the resolved functions.

Copy link
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

Migrates the dataset controller test suite to Ginkgo v2, adds unit tests for dataset reconcile/deletion behaviors, and refactors runtime-controller precheck registration to be lazily resolved to avoid package-init failures.

Changes:

  • Added fake-client unit tests for DatasetReconciler covering finalizer, phase transitions, reference-dataset handling, and deletion flows.
  • Updated dataset envtest suite bootstrap to Ginkgo v2 and added an explicit opt-in env var to skip envtest start failures.
  • Refactored deploy runtime-controller precheck function handling to be lazy/clonable and added tests for lazy resolution + injected prechecks.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/controllers/v1alpha1/dataset/suite_test_helpers_test.go Adds unit test coverage for the envtest-skip gating helper.
pkg/controllers/v1alpha1/dataset/suite_test.go Migrates suite setup to Ginkgo v2 and makes envtest start failure skippable via env var.
pkg/controllers/v1alpha1/dataset/dataset_reconciler_test.go Adds fake-client unit coverage for dataset reconcile and deletion behaviors.
pkg/controllers/deploy/runtime_controllers_test.go Adds tests for lazy precheck resolution and injected prechecks; updates existing expectations/env setup.
pkg/controllers/deploy/runtime_controllers.go Makes runtime precheck discovery lazy and concurrency-safe with cloning.

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

You can also share your feedback on Copilot code review. Take the survey.

@codecov
Copy link

codecov bot commented Mar 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.21%. Comparing base (a69c888) to head (b1356e8).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5683   +/-   ##
=======================================
  Coverage   61.21%   61.21%           
=======================================
  Files         444      444           
  Lines       30540    30540           
=======================================
  Hits        18694    18694           
  Misses      10306    10306           
  Partials     1540     1540           

☔ View full report in Codecov by Sentry.
📢 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.

@hxrshxz hxrshxz marked this pull request as draft March 8, 2026 05:13
@hxrshxz
Copy link
Contributor Author

hxrshxz commented Mar 8, 2026

/gemini review

Copy link
Contributor

@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 is a significant improvement to the test suite. It successfully migrates the dataset controller tests to Ginkgo v2, substantially increases unit test coverage with well-designed test cases, and refactors the runtime precheck discovery to be lazy, which resolves test initialization issues. The code is well-structured and the new tests are thorough. I have one minor suggestion to make a test assertion more explicit.

Comment on lines +303 to +307
getErr := r.Get(ctx, types.NamespacedName{Namespace: "default", Name: "del-clean"}, stored)
// Either the object is deleted (not found) or it exists without the finalizer
if getErr == nil {
Expect(stored.Finalizers).NotTo(ContainElement(finalizer))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The check for object deletion could be more explicit. When the finalizer is removed from an object that has a deletion timestamp, the object should be garbage collected. The fake client from controller-runtime simulates this behavior, so r.Get should return a NotFound error. It would be better to assert this directly to make the test's intent clearer and more robust.

You will need to import k8s.io/apimachinery/pkg/api/errors as apierrors.

Suggested change
getErr := r.Get(ctx, types.NamespacedName{Namespace: "default", Name: "del-clean"}, stored)
// Either the object is deleted (not found) or it exists without the finalizer
if getErr == nil {
Expect(stored.Finalizers).NotTo(ContainElement(finalizer))
}
getErr := r.Get(ctx, types.NamespacedName{Namespace: "default", Name: "del-clean"}, stored)
Expect(apierrors.IsNotFound(getErr)).To(BeTrue())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 1db717d8. The deletion-path test now asserts an explicit NotFound result from the fake client after finalizer removal instead of allowing either outcome.

Copy link
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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


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

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +299 to +307

stored := &datav1alpha1.Dataset{}
getErr := r.Get(ctx, types.NamespacedName{Namespace: "default", Name: "del-clean"}, stored)
Expect(apierrors.IsNotFound(getErr)).To(BeTrue())
})

It("requeues when DatasetRef still has live entries", func() {
now := metav1.Now()
// Create both the main dataset and the referenced dataset in the fake store.
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

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

In this test, getErr is only checked for nil, and any non-nil error (including unexpected ones) will silently pass the assertion. Also, the comment claims the fake client will delete the object after finalizer removal, but controller-runtime's fake client does not emulate GC deletion. Please assert getErr is either nil or apierrors.IsNotFound(getErr), and adjust the comment accordingly (or simply verify the stored object has the finalizer removed when getErr == nil).

Copilot uses AI. Check for mistakes.
@@ -210,6 +329,14 @@ func Test_scaleoutDeploymentIfNeeded(t *testing.T) {
}

func TestScaleoutRuntimeContollerOnDemand(t *testing.T) {
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

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

Typo in test name: TestScaleoutRuntimeContollerOnDemand should be TestScaleoutRuntimeControllerOnDemand for consistency and searchability.

Suggested change
func TestScaleoutRuntimeContollerOnDemand(t *testing.T) {
func TestScaleoutRuntimeControllerOnDemand(t *testing.T) {

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 8, 2026

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.

2 participants