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

refactor(tests): improve x/reports tests using gomock #1184

Merged
merged 2 commits into from
Jun 26, 2023

Conversation

dadamu
Copy link
Contributor

@dadamu dadamu commented Jun 26, 2023

Description

This PR improves the x/reports tests using gomock.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@dadamu dadamu requested a review from a team as a code owner June 26, 2023 09:50
@dadamu dadamu force-pushed the paul/improve-report-gomock branch from 42902b9 to 0660513 Compare June 26, 2023 09:56
@codecov
Copy link

codecov bot commented Jun 26, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (61393a0) 80.79% compared to head (59bc4f3) 80.80%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1184   +/-   ##
=======================================
  Coverage   80.79%   80.80%           
=======================================
  Files         194      194           
  Lines       17310    17310           
=======================================
+ Hits        13986    13987    +1     
  Misses       2727     2727           
+ Partials      597      596    -1     
Impacted Files Coverage Δ
x/reports/keeper/external_hooks.go 68.88% <100.00%> (+2.22%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@dadamu dadamu force-pushed the paul/improve-report-gomock branch 2 times, most recently from f102338 to a89646c Compare June 26, 2023 10:25
Comment on lines +47 to +55

// Delete the reason id key
h.k.DeleteNextReasonID(ctx, subspaceID)

// Delete all the reasons related to this subspace
h.k.IterateSubspaceReasons(ctx, subspaceID, func(reason types.Reason) (stop bool) {
h.k.DeleteReason(ctx, reason.SubspaceID, reason.ID)
return false
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this code moved here instead of keeping it above?

Copy link
Contributor Author

@dadamu dadamu Jun 26, 2023

Choose a reason for hiding this comment

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

DeleteReason also deletes reports containing reasons here, but it causes O(N) since it iterates all the reports when removing a reason, as a result, it makes AfterSubspaceDeleted has O(N^2) time complexity.

Moving this code above can have better performance with O(2N) time complexity since reports containing reasons are removed first.

@dadamu dadamu requested a review from RiccardoM June 26, 2023 14:49
@RiccardoM RiccardoM changed the title chore(tests): improve x/reports tests using gomock refactor(tests): improve x/reports tests using gomock Jun 26, 2023
@RiccardoM RiccardoM merged commit b9e80e9 into master Jun 26, 2023
33 checks passed
@RiccardoM RiccardoM deleted the paul/improve-report-gomock branch June 26, 2023 19:32
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