Skip to content

Add math/rand[/v2] wrappers in tests/antithesis and replace the rand references with the wrappers#22017

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

Add math/rand[/v2] wrappers in tests/antithesis and replace the rand references with the wrappers#22017
nwnt wants to merge 2 commits into
etcd-io:mainfrom
nwnt:add-antithesis-random-wrapper

Conversation

@nwnt

@nwnt nwnt commented Jul 1, 2026

Copy link
Copy Markdown
Member

First step for #21720

I'm adding two wrappers of antithesis's random in which they will be drop-in replacements of math/rand and math/rand/v2. They need to be merged to main first before I can replace all of the occurrences of math/rand[/v2' with them as the server dockerfile clones from main` to build it. In other words, if these don't exist in main, docker build can replace it but won't be able to build because main doesn't contain them.

Once merged, I will follow up with another commit to introduce the sed replacements. Here is an excerpt of what the code looks like after replaced:

diff --git a/pkg/proxy/server.go b/pkg/proxy/server.go
index bc71c3a..6877fcb 100644
--- a/pkg/proxy/server.go
+++ b/pkg/proxy/server.go
@@ -19,7 +19,7 @@ import (
        "errors"
        "fmt"
        "io"
-       mrand "math/rand"
+       mrand "go.etcd.io/etcd/tests/v3/antithesis/pkg/rand"
        "net"
        "net/http"
        "net/url"
diff --git a/pkg/proxy/server_test.go b/pkg/proxy/server_test.go
index 2a7e622..11e1ba9 100644
--- a/pkg/proxy/server_test.go
+++ b/pkg/proxy/server_test.go
@@ -20,7 +20,7 @@ import (
        "fmt"
        "io"
        "log"
-       "math/rand"
+       "go.etcd.io/etcd/tests/v3/antithesis/pkg/rand"
        "net"
        "net/http"
        "net/url"
diff --git a/pkg/stringutil/rand.go b/pkg/stringutil/rand.go
index 347ee7c..db940d8 100644
--- a/pkg/stringutil/rand.go
+++ b/pkg/stringutil/rand.go
@@ -15,7 +15,7 @@
 package stringutil

 import (
-       "math/rand"
+       "go.etcd.io/etcd/tests/v3/antithesis/pkg/rand"
 )

cc @serathius @henrybear327 @ivanvc

@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

@nwnt

nwnt commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

Sorry this took me some time; I actually went with a totally different route implementing a custom ast parser to change the code dynamically since antithesis's random is not a drop-in replace for `math/rand[/v2]'. Later found it way too complicated, and switched back to this approach instead.

@nwnt nwnt force-pushed the add-antithesis-random-wrapper branch from a020e8e to 3e0668c Compare July 1, 2026 04:38
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.70%. Comparing base (1cc3438) to head (134f3e2).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files

see 22 files with indirect coverage changes

@@            Coverage Diff             @@
##             main   #22017      +/-   ##
==========================================
- Coverage   69.76%   69.70%   -0.07%     
==========================================
  Files         449      449              
  Lines       38163    38177      +14     
==========================================
- Hits        26626    26610      -16     
- Misses      10112    10140      +28     
- Partials     1425     1427       +2     

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 1cc3438...134f3e2. Read the comment docs.

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

@nwnt

nwnt commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

/retest

@nwnt nwnt force-pushed the add-antithesis-random-wrapper branch from 3e0668c to 4c78eef Compare July 1, 2026 12:40
Signed-off-by: Nont <9658731+nwnt@users.noreply.github.com>
@nwnt nwnt force-pushed the add-antithesis-random-wrapper branch from 4c78eef to d34dbdc Compare July 1, 2026 12:47
@nwnt

nwnt commented Jul 5, 2026

Copy link
Copy Markdown
Member Author

Content of all go mod with replace. tests/antithesis/pkg/go.mod is not replaced.

./tools/testgrid-analysis/go.mod:replace math/rand => /etcd/tests/antithesis/pkg/rand
./tools/testgrid-analysis/go.mod:replace math/rand/v2 => /etcd/tests/antithesis/pkg/rand/v2
./tools/rw-heatmaps/go.mod:replace math/rand => /etcd/tests/antithesis/pkg/rand
./tools/rw-heatmaps/go.mod:replace math/rand/v2 => /etcd/tests/antithesis/pkg/rand/v2
./tools/mod/go.mod:replace math/rand => /etcd/tests/antithesis/pkg/rand
./tools/mod/go.mod:replace math/rand/v2 => /etcd/tests/antithesis/pkg/rand/v2
./tests/go.mod:replace (
./tests/go.mod:replace math/rand => /etcd/tests/antithesis/pkg/rand
./tests/go.mod:replace math/rand/v2 => /etcd/tests/antithesis/pkg/rand/v2
./tests/go.mod:replace antithesis.notifier/zf30236f66c6a => ../../notifier
./server/go.mod:replace (
./server/go.mod:replace math/rand => /etcd/tests/antithesis/pkg/rand
./server/go.mod:replace math/rand/v2 => /etcd/tests/antithesis/pkg/rand/v2
./server/go.mod:replace antithesis.notifier/zf30236f66c6a => ../../notifier
./pkg/go.mod:replace go.etcd.io/etcd/client/pkg/v3 => ../client/pkg
./pkg/go.mod:replace math/rand => /etcd/tests/antithesis/pkg/rand
./pkg/go.mod:replace math/rand/v2 => /etcd/tests/antithesis/pkg/rand/v2
./pkg/go.mod:replace antithesis.notifier/zf30236f66c6a => ../../notifier
./go.mod:replace (
./go.mod:replace math/rand => /etcd/tests/antithesis/pkg/rand
./go.mod:replace math/rand/v2 => /etcd/tests/antithesis/pkg/rand/v2
./go.mod:replace antithesis.notifier/zf30236f66c6a => ../notifier
./etcdutl/go.mod:replace (
./etcdutl/go.mod:replace math/rand => /etcd/tests/antithesis/pkg/rand
./etcdutl/go.mod:replace math/rand/v2 => /etcd/tests/antithesis/pkg/rand/v2
./etcdutl/go.mod:replace antithesis.notifier/zf30236f66c6a => ../../notifier
./etcdctl/go.mod:replace (
./etcdctl/go.mod:replace math/rand => /etcd/tests/antithesis/pkg/rand
./etcdctl/go.mod:replace math/rand/v2 => /etcd/tests/antithesis/pkg/rand/v2
./etcdctl/go.mod:replace antithesis.notifier/zf30236f66c6a => ../../notifier
./etcd/tools/testgrid-analysis/go.mod:replace math/rand => /etcd/tests/antithesis/pkg/rand
./etcd/tools/testgrid-analysis/go.mod:replace math/rand/v2 => /etcd/tests/antithesis/pkg/rand/v2
./etcd/tools/testgrid-analysis/go.mod:replace antithesis.notifier/zf30236f66c6a => ../../../../notifier
./etcd/tools/rw-heatmaps/go.mod:replace math/rand => /etcd/tests/antithesis/pkg/rand
./etcd/tools/rw-heatmaps/go.mod:replace math/rand/v2 => /etcd/tests/antithesis/pkg/rand/v2
./etcd/tools/rw-heatmaps/go.mod:replace antithesis.notifier/zf30236f66c6a => ../../../../notifier
./etcd/tests/antithesis/pkg/go.mod:replace antithesis.notifier/zf30236f66c6a => ../../../../../notifier
./etcd/client/v3/go.mod:replace (
./etcd/client/v3/go.mod:replace math/rand => /etcd/tests/antithesis/pkg/rand
./etcd/client/v3/go.mod:replace math/rand/v2 => /etcd/tests/antithesis/pkg/rand/v2
./etcd/client/v3/go.mod:replace antithesis.notifier/zf30236f66c6a => ../../../../notifier
./etcd/client/pkg/go.mod:replace math/rand => /etcd/tests/antithesis/pkg/rand
./etcd/client/pkg/go.mod:replace math/rand/v2 => /etcd/tests/antithesis/pkg/rand/v2
./etcd/client/pkg/go.mod:replace antithesis.notifier/zf30236f66c6a => ../../../../notifier
./client/v3/go.mod:replace (
./client/v3/go.mod:replace math/rand => /etcd/tests/antithesis/pkg/rand
./client/v3/go.mod:replace math/rand/v2 => /etcd/tests/antithesis/pkg/rand/v2
./client/pkg/go.mod:replace math/rand => /etcd/tests/antithesis/pkg/rand
./client/pkg/go.mod:replace math/rand/v2 => /etcd/tests/antithesis/pkg/rand/v2
./cache/go.mod:replace (
./cache/go.mod:replace math/rand => /etcd/tests/antithesis/pkg/rand
./cache/go.mod:replace math/rand/v2 => /etcd/tests/antithesis/pkg/rand/v2
./cache/go.mod:replace antithesis.notifier/zf30236f66c6a => ../../notifier
./api/go.mod:replace math/rand => /etcd/tests/antithesis/pkg/rand
./api/go.mod:replace math/rand/v2 => /etcd/tests/antithesis/pkg/rand/v2
./api/go.mod:replace antithesis.notifier/zf30236f66c6a => ../../notifier

@nwnt nwnt force-pushed the add-antithesis-random-wrapper branch from 634e592 to 81b4696 Compare July 5, 2026 04:50
@nwnt

nwnt commented Jul 5, 2026

Copy link
Copy Markdown
Member Author

@serathius this should be ready for another review now. Let me know if it's better to split them into a smaller PR.

@nwnt nwnt force-pushed the add-antithesis-random-wrapper branch from 81b4696 to 28558dc Compare July 5, 2026 05:24
@nwnt nwnt changed the title Add math/rand/v2 wrapper in tests/antithesis Add math/rand[/v2] wrappers in tests/antithesis and replace the rand references with the wrappers Jul 5, 2026
@nwnt nwnt force-pushed the add-antithesis-random-wrapper branch 2 times, most recently from 9ae3c7b to 6a8f06d Compare July 5, 2026 05:35
Signed-off-by: Nont <9658731+nwnt@users.noreply.github.com>
@nwnt nwnt force-pushed the add-antithesis-random-wrapper branch from 6a8f06d to 134f3e2 Compare July 5, 2026 05:41
Comment thread tests/go.mod
require (
github.com/anishathalye/porcupine v1.1.0
github.com/antithesishq/antithesis-sdk-go v0.4.3
github.com/antithesishq/antithesis-sdk-go v0.7.2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you split the PR to update the dependency? As you pointed out during meeting there were problems with package stability. Let's test new package version first.

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.

Yep, raised #22045 for this.

@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-coverage-report 134f3e2 link true /test pull-etcd-coverage-report
pull-etcd-e2e-amd64 134f3e2 link true /test pull-etcd-e2e-amd64

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.

2 participants