Skip to content

test: fix fuzzer logic for ImageListPullJob status generation#2454

Open
rakshaak29 wants to merge 1 commit into
openkruise:masterfrom
rakshaak29:fix/fuzzer-imagelistpulljob-status
Open

test: fix fuzzer logic for ImageListPullJob status generation#2454
rakshaak29 wants to merge 1 commit into
openkruise:masterfrom
rakshaak29:fix/fuzzer-imagelistpulljob-status

Conversation

@rakshaak29

Copy link
Copy Markdown
Contributor

What's changed?

This PR addresses a logical flaw in the fuzzer implementation for ImageListPullJob (test/fuzz/imagelistpulljob.go) that was restricting test coverage.

Previously, the random number generator used r.Intn(1) to generate the Active, Succeeded, and Completed status fields. According to the Go math/rand specification, rand.Intn(n) returns a value in the half-open interval [0, n). Therefore, r.Intn(1) always returns 0. This entirely prevented the fuzzer from generating test configurations where these status fields had a value of 1 or greater.

This commit changes the bounds to r.Intn(2), allowing the status variables to properly simulate both 0 and 1 states during fuzz testing, ultimately increasing the fuzzer's effectiveness at detecting latent bugs.

How to test it?

  1. Check out this branch.
  2. Run make test to ensure all tests pass.
  3. Run staticcheck ./test/fuzz/... to verify that the SA4030 warning (which initially highlighted that r.Intn(1) always returns 0) has been cleared.

Which issue(s) this PR fixes:

#2453

Signed-off-by: rakshaak29 <rakshaak29@gmail.com>
Copilot AI review requested due to automatic review settings May 13, 2026 06:53
@kruise-bot kruise-bot requested review from Fei-Guo and veophi May 13, 2026 06:53
@kruise-bot

Copy link
Copy Markdown

[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 veophi for approval by writing /assign @veophi 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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes ImageListPullJob fuzzer status generation in test/fuzz/imagelistpulljob.go by correcting rand.Intn upper bounds so the fuzzer can actually produce both 0 and 1 values for key status counters (instead of always 0).

Changes:

  • Update Active, Succeeded, and Completed status field generation from r.Intn(1) to r.Intn(2) to avoid always returning 0.
  • Improve fuzz input variability for ImageListPullJobStatus, increasing the chance of exercising additional code paths during fuzzing.

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

@codecov

codecov Bot commented May 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 48.99%. Comparing base (749e8f2) to head (dabae42).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2454      +/-   ##
==========================================
+ Coverage   48.77%   48.99%   +0.21%     
==========================================
  Files         324      325       +1     
  Lines       27928    28032     +104     
==========================================
+ Hits        13623    13734     +111     
+ Misses      12775    12746      -29     
- Partials     1530     1552      +22     
Flag Coverage Δ
unittests 48.99% <ø> (+0.21%) ⬆️

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

☔ 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.

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

Labels

size/XS size/XS: 0-9

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants