-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
docs: add comments for funcs #22271
docs: add comments for funcs #22271
Conversation
📝 WalkthroughWalkthroughThe changes in this pull request introduce multiple new test functions and methods within the Changes
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (12)
simsx/slices_test.go (3)
Line range hint
10-19
: LGTM! Consider adding a negative test case.The
TestCollect
function is well-implemented and covers both same-type and type-conversion scenarios. The comments provide clear explanations, and the assertions are correct.Consider adding a negative test case to ensure the function behaves correctly with an empty slice input:
assert.Empty(t, Collect([]int{}, func(a int) int { return a * 2 }))
20-27
: LGTM! Consider adding an edge case test.The
TestFirst
function is well-implemented, covering both positive and negative scenarios. The comments are clear, and the assertions are correct.Consider adding an edge case test for an empty slice input:
assert.Nil(t, First([]string{}, func(a string) bool { return true }))
Line range hint
28-40
: LGTM! Consider adding an edge case test.The
TestOneOf
function is well-implemented, covering different slice types and using a mock random number generator effectively. The comments are clear, and the assertions are correct.Consider adding an edge case test for an empty slice input:
assert.Panics(t, func() { OneOf(randMock{next: 0}, []string{}) })This test ensures that the function panics when given an empty slice, which is the expected behavior for the
OneOf
function.simsx/reporter_test.go (2)
Line range hint
138-160
: Enhance clarity by renaming the helper function.In
TestSkipHook
, consider renaming themyHook
function to something more descriptive likecreateSkipHook
to better convey its purpose of creating a skip hook and tracking its invocation. This improves code readability and maintainability.
Line range hint
162-204
: Extend test coverage for summary generation.While
TestReporterSummary
covers key scenarios for skipped and successful operations, consider adding test cases that cover more diverse error conditions and edge cases. This would ensure comprehensive testing of the summary generation functionality under various circumstances.simsx/registry_test.go (4)
Line range hint
57-58
: Improve error handling in test casesIn the "error in delivery execution" test case, consider checking and asserting the error returned by
fn
to ensure that the expected delivery error is properly handled and tested.
Line range hint
161-173
: Avoid usingpanic
in test functionsUsing
panic("not implemented")
in test functions is discouraged as it can abruptly terminate tests. Instead, consider usingt.Skip("implementation pending")
or returning an error to indicate unimplemented functionality.Apply this diff to replace
panic
witht.Skip
:-f1 := func(ctx context.Context, testData *ChainDataSource, reporter SimulationReporter) (signer []SimAccount, msg sdk.Msg) { - panic("not implemented") -} +f1 := func(ctx context.Context, testData *ChainDataSource, reporter SimulationReporter) (signer []SimAccount, msg sdk.Msg) { + t.Skip("implementation pending") + return nil, nil +}Repeat this change for all instances where
panic("not implemented")
is used.
Line range hint
179-201
: Replacepanic
with appropriate test placeholdersIn
TestAppendIterators
, the anonymous functions usepanic("not implemented")
. This is not recommended in test code as it can cause unexpected failures. Uset.Skip
or provide minimal implementations instead.Update the functions as follows:
-func(ctx context.Context, testData *ChainDataSource, reporter SimulationReporter) (signer []SimAccount, msg sdk.Msg) { - panic("not implemented") -} +func(ctx context.Context, testData *ChainDataSource, reporter SimulationReporter) (signer []SimAccount, msg sdk.Msg) { + t.Skip("implementation pending") + return nil, nil +}
Line range hint
203-209
: Consider handling empty iterators inreadAll
The
readAll
function does not handle the case where the iterator might be empty. Although it will return an empty slice, explicitly checking for an empty iterator can improve code clarity and maintainability.simsx/reporter.go (3)
Line range hint
141-145
: Eliminate unnecessaryelse
statement for cleaner codeSince the
if
block ends with areturn
, theelse
is unnecessary and can be removed to reduce nesting and improve readability.Here's the suggested change:
if err == nil { return simtypes.NewOperationMsgBasic(x.module, x.msgTypeURL, x.Comment(), true) - } else { + } return simtypes.NewOperationMsgBasic(x.module, x.msgTypeURL, x.Comment(), false) }
Line range hint
166-170
: Unusedmsg
parameter inSuccess
methodThe
msg
parameter is not used within theSuccess
method. Consider utilizingmsg
if it's intended to affect the reporter's state or remove it if it's unnecessary.
Line range hint
248-263
: Potential issues withslices.Sorted
andslices.Collect
functionsThe
slices
package in Go standard library does not haveSorted
orCollect
functions. This could lead to compilation errors. Consider usingslices.Sort
for in-place sorting and remove or replaceslices.Collect
.Here's the suggested modification:
- keys := slices.Sorted(maps.Keys(s.counts)) + keys := maps.Keys(s.counts) + slices.Sort(keys)And adjust the loop accordingly:
- values := maps.Values(c) - keys := maps.Keys(c) - sb.WriteString(fmt.Sprintf("%d\t%s: %q\n", sum(slices.Collect(values)), m, slices.Collect(keys))) + total := sum(maps.Values(c)) + reasons := maps.Keys(c) + sb.WriteString(fmt.Sprintf("%d\t%s: %q\n", total, m, reasons))
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
📒 Files selected for processing (4)
- simsx/registry_test.go (5 hunks)
- simsx/reporter.go (7 hunks)
- simsx/reporter_test.go (6 hunks)
- simsx/slices_test.go (3 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
simsx/registry_test.go (2)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Pattern
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"simsx/reporter.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.simsx/reporter_test.go (2)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Pattern
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"simsx/slices_test.go (2)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Pattern
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"
🔇 Additional comments (17)
simsx/slices_test.go (2)
41-47
: LGTM! The mock type is well-implemented.The
randMock
type and itsIntn
method are correctly implemented to serve as a mock random number generator for testing purposes. The comment for theIntn
method is clear and accurate.
Line range hint
1-47
: Overall, excellent additions to the test suite!The new test functions (
TestCollect
,TestFirst
, andTestOneOf
) significantly enhance the test coverage of thesimsx
package. The implementations follow Go testing best practices, with clear comments, appropriate test cases, and correct assertions. The introduction of therandMock
type for controlled testing of random selection is a good approach.These changes contribute to a more robust and reliable codebase by ensuring the correct functionality of the
Collect
,First
, andOneOf
functions across various scenarios.simsx/reporter_test.go (2)
Line range hint
14-73
: Comprehensive addition of test cases forSimulationReporter
.The
TestSimulationReporterToLegacy
function adds thorough test coverage for convertingSimulationReporter
to the legacyOperationMsg
format. It effectively covers scenarios like initialization, success, failure, and handling multiple errors, enhancing the robustness of the testing suite.
Line range hint
74-136
: Robust testing of state transitions inSimulationReporter
.The
TestSimulationReporterTransitions
function methodically tests valid and invalid state transitions, ensuring that theSimulationReporter
maintains correct status and panics appropriately on invalid transitions. This contributes to the reliability and stability of the reporter's state management.simsx/registry_test.go (1)
20-21
: Function comment follows Go conventionsThe comment for
TestSimsMsgRegistryAdapter
appropriately starts with the function name and clearly describes its purpose, adhering to Go's commenting guidelines.simsx/reporter.go (12)
121-123
: LGTM!The
Skip
method correctly updates the status toskipped
with the provided comment.
126-128
: LGTM!The
Skipf
method correctly formats the comment and delegates toSkip
.
131-133
: LGTM!The
IsSkipped
method accurately checks if the operation has been skipped or completed.
Line range hint
156-162
: LGTM!The
Fail
method correctly updates the status tocompleted
, captures the error, and ensures thread safety.
176-180
: LGTM!The
Close
method properly finalizes the reporter and returns any captured error, ensuring thread safety.
Line range hint
184-205
: LGTM!The
toStatus
method correctly updates the reporter's status atomically and handles callbacks appropriately.
207-211
: LGTM!The
Comment
method returns the concatenated comments, ensuring thread safety with read locks.
214-216
: LGTM!The
Summary
method correctly returns the execution summary.
219-223
: LGTM!The
ExecutionSummary
struct is properly defined with synchronization primitives for concurrent access.
226-228
: LGTM!The
NewExecutionSummary
function correctly initializes theExecutionSummary
struct.
Line range hint
231-244
: LGTM!The
Add
method updates the execution summary accurately, handling counts and skip reasons with proper synchronization.
Line range hint
268-272
: LGTM!The
sum
function correctly calculates the sum of a slice of integers.
@@ -11,6 +11,7 @@ import ( | |||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation" | |||
) | |||
|
|||
// TestSimulationReporterToLegacy tests the conversion of SimulationReporter to the legacy OperationMsg format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discrepancy between PR description and code changes.
The PR description mentions adding comments for functions to enhance documentation. However, this code introduces multiple new test functions, which extends beyond documentation updates. Please ensure the PR description accurately reflects the scope of the changes for clarity.
Hey, we don't need comments on those tests, thanks! |
Description
add comments for funcs
Summary by CodeRabbit
New Features
Bug Fixes
Documentation