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

Write TestRandom util #976

Merged
merged 5 commits into from
Dec 11, 2024
Merged

Write TestRandom util #976

merged 5 commits into from
Dec 11, 2024

Conversation

litt3
Copy link
Contributor

@litt3 litt3 commented Dec 10, 2024

Why are these changes needed?

  • The existing random test utils in common/testutils/test_utils.go operate by seeding global rand. This isn't ideal, as it doesn't provide a source of randomness that can be passed into objects during testing.
  • This PR creates a new utility class, which provides the same random utility methods from test_utils.go, but with a non-global instance of random.
  • If this PR merges, I will open subsequent PRs to migrate usage of newly deprecated test methods.
  • I created this new utility to provide functionality necessary to address this comment in an ongoing PR.
  • I've discussed this approach with @cody-littley.

Checks

  • I've made sure the tests are passing. Note that there might be a few flaky tests, in that case, please comment that they are not relevant.
  • I've checked the new test coverage and the coverage percentage didn't drop.
  • Testing Strategy
    • Unit tests
    • Integration tests
    • This PR is not tested :(

@litt3 litt3 requested a review from cody-littley December 10, 2024 18:09
@litt3 litt3 self-assigned this Dec 10, 2024
@litt3 litt3 marked this pull request as ready for review December 10, 2024 19:39
Copy link
Contributor

@samlaf samlaf left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, but have a few nits

common/testutils/test_random.go Outdated Show resolved Hide resolved
common/testutils/test_random.go Outdated Show resolved Hide resolved
common/testutils/test_random.go Outdated Show resolved Hide resolved
@litt3 litt3 requested review from cody-littley and samlaf December 10, 2024 20:50
Copy link
Contributor

@samlaf samlaf left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines 32 to 35
// GetRand returns the underlying random instance
func (r *TestRandom) GetRand() *rand.Rand {
return r.Rand
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: getter is not needed with a public field

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@litt3 litt3 merged commit 3eb67af into Layr-Labs:master Dec 11, 2024
6 checks passed
@litt3 litt3 deleted the testrandom-util branch December 11, 2024 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants