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

improve example test by sorting output #1366

Merged
merged 3 commits into from
Sep 10, 2024

Conversation

ketsiambaku
Copy link
Contributor

@ketsiambaku ketsiambaku commented Sep 10, 2024

What changed?
Improving the example test by sorting the activities returned by Stats()
The example implementation range over a map and return the result in a slice. Because of this, the assertion against expected result would not always pass since the order is random. This made the test flaky

Why?

How did you test it?
unit tests

Potential risks

Copy link

codecov bot commented Sep 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (master@fd9956a). Learn more about missing BASE report.
Report is 1 commits behind head on master.

Additional details and impacted files

Continue to review full report in Codecov by Sentry.

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

@@ -75,6 +77,9 @@ func (ati *activityTrackerImpl) Stats() Activities {
}{Info: a, Count: count})
}
}
sort.Slice(activities, func(i, j int) bool {
return strings.Compare(strings.ToLower(activities[i].Info.ActivityType), strings.ToLower(activities[j].Info.ActivityType)) < 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorting makes perfect sense, but there's no reason to ToLower here afaict. It'll just make things more ambiguous than they are IRL, where strings need to be identical in both workers and example-test output checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

Copy link
Contributor

@Groxx Groxx left a comment

Choose a reason for hiding this comment

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

From the docs on strings.Compare it looks like we can/probably should just use < here... but they appear to be semantically identical so I'll stamp now and land whichever you prefer :) thankfully it's not a locale-sensitive comparison at least.

@ketsiambaku ketsiambaku merged commit 74f6915 into uber-go:master Sep 10, 2024
13 checks passed
@ketsiambaku
Copy link
Contributor Author

From the docs on strings.Compare it looks like we can/probably should just use < here... but they appear to be semantically identical so I'll stamp now and land whichever you prefer :) thankfully it's not a locale-sensitive comparison at least.

I saw the last comment after merging. Followed up in #1367

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.

2 participants