Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testutil: replace math/rand deprecation #2850

Merged

Conversation

KaloyanTanev
Copy link
Contributor

  • Update global rand.Seed(x) with local rand.New(rand.NewSource(x));
  • Update test random functions that used global seed with local seed;
  • Update math/rand.Read(x) with crypto/rand.Read(x) (not included in the issue, but deprecated as well).

category: refactor
ticket: #2831

@pinebit
Copy link
Contributor

pinebit commented Feb 5, 2024

@KaloyanTanev thank you for the contribution. You can run pre-commit locally before making a commit to determine possible issues or potential test failures.
Please check and address the issues reported by linter:

  Error: Error return value of `rand.Read` is not checked (errcheck)
  Error: test helper function should start from t.Helper() (thelper)
  Error: test helper function should start from t.Helper() (thelper)
  Error: test helper function should start from t.Helper() (thelper)

p.s. some tests are known to be flakey, like *qbft* and TestSimnetDuties/sync_committee_with_teku.

Copy link

codecov bot commented Feb 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (cfe844b) 53.44% compared to head (2acc741) 53.40%.
Report is 2 commits behind head on main.

❗ Current head 2acc741 differs from pull request most recent head 1332a6b. Consider uploading reports for the commit 1332a6b to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2850      +/-   ##
==========================================
- Coverage   53.44%   53.40%   -0.05%     
==========================================
  Files         200      200              
  Lines       28011    28034      +23     
==========================================
+ Hits        14971    14972       +1     
- Misses      11180    11208      +28     
+ Partials     1860     1854       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@KaloyanTanev
Copy link
Contributor Author

Hi @pinebit , wasn't aware of the pre-commit, thanks. I've ran only go test ./... -failfast -race locally. Is there anything else I should check before pushing?

Fixed the linting.

@xenowits
Copy link
Contributor

xenowits commented Feb 5, 2024

@KaloyanTanev you should install pre-commit pre-commit install and then run pre-commit run --all-files

This should report all possible linting errors that you're having rn

Copy link
Collaborator

@gsora gsora left a comment

Choose a reason for hiding this comment

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

LFTM, good to merge once linter issues are fixed.

@pinebit
Copy link
Contributor

pinebit commented Feb 5, 2024

@KaloyanTanev
The linter is still reporting a few issues:

  Error: test helper function should start from t.Helper() (thelper)
  Error: test helper function should start from t.Helper() (thelper)
  Error: test helper function should start from t.Helper() (thelper)

Copy link

sonarcloud bot commented Feb 5, 2024

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
2.0% Duplication on New Code

See analysis details on SonarCloud

@KaloyanTanev
Copy link
Contributor Author

Hmmm, a bit weird as locally the pre-commit run --all-files passed.

➜  charon git:(kalo/update-deprecated-seed) ✗ pre-commit run --all-files
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
mixed line ending........................................................Passed
don't commit to branch...................................................Passed
check for go version.....................................................Passed
check if file has licence text appended as header........................Passed
fiximports...............................................................Passed
go-mod-tidy..............................................................Passed
go fmt...................................................................Passed
golangci-lint............................................................Passed
run-go-tests.............................................................Passed
run-buf..................................................................Passed
run-regexp...............................................................Passed
run-testutil.............................................................Passed

However, running golangci-lint on its own gave me the expected linting errors:

➜  charon git:(kalo/update-deprecated-seed) ✗ golangci-lint run   
testutil/random.go:1205:6: test helper function should start from t.Helper() (thelper)
func RandomCoreAttestationData(t *testing.T) core.AttestationData {
     ^
testutil/random.go:1221:6: test helper function should start from t.Helper() (thelper)
func RandomUnsignedDataSet(t *testing.T) core.UnsignedDataSet {
     ^
cluster/test_cluster.go:188:6: test helper function should start from t.Helper() (thelper)
func RandomRegistration(t *testing.T, network string) BuilderRegistration {
     ^

I think it should be good after latest commit.

@pinebit
Copy link
Contributor

pinebit commented Feb 5, 2024

Hmmm, a bit weird as locally the pre-commit run --all-files passed.

Thank you @KaloyanTanev for the effort. Running a new build now, and if it succeeds we will get it merged.
Good job on the ticket!

@KaloyanTanev
Copy link
Contributor Author

@pinebit I see one of the unit tests failed - TestRawRouter/get_validators_with_post/empty_parameters. Is it one of the known flaky tests or shall I have a look at it?

@pinebit
Copy link
Contributor

pinebit commented Feb 5, 2024

@pinebit I see one of the unit tests failed - TestRawRouter/get_validators_with_post/empty_parameters. Is it one of the known flaky tests or shall I have a look at it?

This seems to be one bug I likely introduced today :(
JSON serialization is not stable, therefore these checks need to be improved (we cannot rely on 0 and 1 indexes)

			require.EqualValues(t, eth2p0.ValidatorIndex(12), resp.Data[0].Index)
			require.EqualValues(t, eth2p0.ValidatorIndex(35), resp.Data[1].Index)

in router_internal_test.go

@pinebit
Copy link
Contributor

pinebit commented Feb 5, 2024

@KaloyanTanev I created separate PR for this issue #2857 because our main is also broken. Your build should succeed eventually.

@pinebit pinebit added the merge when ready Indicates bulldozer bot may merge when all checks pass label Feb 5, 2024
@obol-bulldozer obol-bulldozer bot merged commit 9804c83 into ObolNetwork:main Feb 5, 2024
11 checks passed
obol-bulldozer bot pushed a commit that referenced this pull request Jul 25, 2024
golangci-lint was on older version that did not support go1.22 yet, which causes false alarms.

---

This update introduced a lot of new, deprecated and modified linters. There are a lot of changes in the files and I would advise for easier review to go over the commits, as I've tried to keep them concise, so there are only changes from one linter or if many, the changes are little. Most eye catching changes in the files are:

- `testifylint`: we had quite a lot of assertions inside of go routines, this is a bit of a red flag, because as observed in [this small example](https://go.dev/play/p/WoBGMiKQDEk), a failed assertion might or might not be caught
- The `golangci-lint` used in pre-commit was a default `golangci-lint` from [here](https://github.com/golangci/golangci-lint), using its default config, which made the linter pass locally all the time. This is something I've observed multiple times ([dating back to my very first PR](#2850 (comment)) :)). Now the pre-commit hook is running the locally installed `golangci-lint` tool and it checks if the version is the same as the one in the pipelines.
- Added `max-same-issues=0` and `max-issues-per-linter=0` so there is no limit on what we see in the output. Previously the default of 3 was used, so if there were hundreds of errors with one linter, it would have displayed only 3, which made it quite a hassle to fix.
- Bump the `golangci-lint` action's version to v6. It now points where exactly the issue is, which is great!

category: fixbuild
ticket: #3179
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge when ready Indicates bulldozer bot may merge when all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants