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

Use ids.GenerateTestID helper in tests #3165

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

dhrubabasu
Copy link
Contributor

Why this should be merged

We hardcode random byte slices in a lot of the tests. Let's use the helper we have already instead :)

How this works

Replace hard-coded byte slices with ids.GenerateTestID()

How this was tested

CI

@dhrubabasu dhrubabasu added testing This primarily focuses on testing cleanup Code quality improvement labels Jul 2, 2024
@dhrubabasu dhrubabasu added this to the v1.11.9 milestone Jul 2, 2024
@dhrubabasu dhrubabasu self-assigned this Jul 2, 2024
Copy link
Contributor

@ARR4N ARR4N left a comment

Choose a reason for hiding this comment

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

Approving with requested changes (use fmt.Sprintf() instead of strings.Replace()) as I don't need to re-review them, but please address before merging.

@@ -1262,7 +1262,7 @@ func TestStateSyncIsStoppedIfEnoughVotesAreCastedWithNoClearMajority(t *testing.
context.Background(),
voterID,
reqID,
set.Of(ids.ID{'u', 'n', 'k', 'n', 'o', 'w', 'n', 'I', 'D'}),
set.Of(ids.GenerateTestID()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Was it ever useful in debugging to have these kinds of "labelled" ids? If so, you could add ids.GenerateLabelledTestID(tb testing.TB, lbl string) that then calls tb.Logf("test ID %q: %v", lbl, id) before returning the value.

The only problem I see with this would be introducing the testing package into prod code.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is completely optional and dependent on the answer to my opening question.

@@ -142,20 +145,23 @@ func TestBanffProposalBlockJSON(t *testing.T) {
simpleBanffProposalBlockBytes, err := json.MarshalIndent(simpleBanffProposalBlock, "", "\t")
require.NoError(err)

require.Equal(`{
expectedSimpleBanffProposalBlockString := `{
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be clearer if it used fmt.Sprintf() instead of strings.Replace().

(optional, subjective) You could use explicit arg indices if it makes it more readable, but I'm not sure that it will.

Copy link
Contributor

Choose a reason for hiding this comment

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

TIL about explicit arg indicies

@@ -186,7 +192,7 @@ func TestBanffProposalBlockJSON(t *testing.T) {
complexBanffProposalBlockBytes, err := json.MarshalIndent(complexBanffProposalBlock, "", "\t")
require.NoError(err)

require.Equal(`{
expectedComplexBanffProposalBlockString := `{
Copy link
Contributor

Choose a reason for hiding this comment

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

As above re fmt.Sprintf().

@StephenButtolph StephenButtolph modified the milestones: v1.11.9, v1.11.10 Jul 3, 2024
Copy link
Contributor

@StephenButtolph StephenButtolph left a comment

Choose a reason for hiding this comment

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

Are there any cases here where this introduces a weird dependency on the sorted-ness of IDs returned by ids.GenerateTestID()?

snow/consensus/snowman/poll/set_test.go Outdated Show resolved Hide resolved
@@ -142,20 +145,23 @@ func TestBanffProposalBlockJSON(t *testing.T) {
simpleBanffProposalBlockBytes, err := json.MarshalIndent(simpleBanffProposalBlock, "", "\t")
require.NoError(err)

require.Equal(`{
expectedSimpleBanffProposalBlockString := `{
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL about explicit arg indicies

@dhrubabasu dhrubabasu marked this pull request as draft July 26, 2024 19:24
@dhrubabasu
Copy link
Contributor Author

Converting to draft for now, there seems to be dependencies in the codebase already that rely on the sorted-ness of the IDs returned. Will investigate further.

@dhrubabasu dhrubabasu removed this from the v1.11.11 milestone Aug 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code quality improvement testing This primarily focuses on testing
Projects
Status: Paused 🧊
Development

Successfully merging this pull request may close these issues.

None yet

3 participants