Skip to content

Use antithesis's random#21989

Open
nwnt wants to merge 2 commits into
etcd-io:mainfrom
nwnt:use-antithesis-random
Open

Use antithesis's random#21989
nwnt wants to merge 2 commits into
etcd-io:mainfrom
nwnt:use-antithesis-random

Conversation

@nwnt

@nwnt nwnt commented Jun 22, 2026

Copy link
Copy Markdown
Member

Fixes #21720

Instead of rolling my own implementation, I'm making everything that uses math/rand become something like the following:

   // original
   num := rand.Intn()
   // patched
   num := rand.New(antithesisRand.Source()).Intn()

which should satisfy the requirements described here.

The patch is a bit large because I did not want to write a small program or script to patch everything on the fly just yet as there are a lot of different usages of math/rand. That might be something to do in the future once we have proven that this work. The files and usages are looked up by the following command:

rg -l math/rand | grep -v _test.go | sort

cc @serathius @marcus-hodgson-antithesis @henrybear327

@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: nwnt
Once this PR has been reviewed and has the lgtm label, please assign serathius for approval. For more information see the 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

Comment thread tests/antithesis/server/Dockerfile Outdated
Comment on lines +26 to +30
# inject assertions in place of gofail
WORKDIR /etcd/server
RUN go install golang.org/x/tools/cmd/goimports@latest
RUN go get github.com/antithesishq/antithesis-sdk-go@v0.4.4
RUN for file in $(grep -rl '// gofail'); do sed -i 's|\/\/ gofail.*var \([[:alnum:]]*\) .*|assert\.Reachable("\1", nil)|' $file; goimports -w $file; done

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This move is needed because otherwise the patch would run into an error. Basically we just need to sed after the patch.

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.61%. Comparing base (b9ba05c) to head (b6c66dc).

Additional details and impacted files

see 17 files with indirect coverage changes

@@            Coverage Diff             @@
##             main   #21989      +/-   ##
==========================================
- Coverage   69.66%   69.61%   -0.05%     
==========================================
  Files         449      449              
  Lines       38177    38177              
==========================================
- Hits        26596    26577      -19     
- Misses      10149    10167      +18     
- Partials     1432     1433       +1     

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b9ba05c...b6c66dc. Read the comment docs.

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

@serathius

Copy link
Copy Markdown
Member

We don't want a large patch, can we just run sed to replace math/rand import with antithesis one? Are there incompatible differences that prevent us from doing so?

@nwnt

nwnt commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

We can't actually do that willy-nilly as Antithesis's random package is not a drop-in replacement of Go's math/random.

Let me think if there's a way to do so, but that might involve a script, which I can try to make it small.

nwnt added 2 commits July 4, 2026 23:38
Signed-off-by: Nont <9658731+nwnt@users.noreply.github.com>
Signed-off-by: Nont <9658731+nwnt@users.noreply.github.com>
@nwnt nwnt force-pushed the use-antithesis-random branch from 1d5dab8 to b6c66dc Compare July 5, 2026 04:41
@kubernetes-prow kubernetes-prow Bot added size/L and removed size/XL labels Jul 5, 2026
@kubernetes-prow

Copy link
Copy Markdown

@nwnt: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-etcd-verify b6c66dc link true /test pull-etcd-verify
pull-etcd-coverage-report b6c66dc link true /test pull-etcd-coverage-report

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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-sigs/prow repository. I understand the commands that are listed here.

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

Development

Successfully merging this pull request may close these issues.

Antithesis tests should use /dev/random rather than the math/rand package

2 participants