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

x/gov/keeper: fix flaky TestPaginatedVotesQuery #9223

Merged
merged 1 commit into from
Apr 28, 2021
Merged

x/gov/keeper: fix flaky TestPaginatedVotesQuery #9223

merged 1 commit into from
Apr 28, 2021

Conversation

cuonglm
Copy link
Contributor

@cuonglm cuonglm commented Apr 28, 2021

Description

When testing with -race, sometimes the random source generate the same
string for consecutive calls, causing duplicated voter address. So the
number of votes in DB is not 20.

To fix this, we ensure unique addresses are generated, by using a map
for tracking which one was produced, and skip the duplicated address and
generated new one. Testing with:

go test -race -v -count=1000 -run=TestPaginatedVotesQuery

now passes.

Updates #9010


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@cuonglm
Copy link
Contributor Author

cuonglm commented Apr 28, 2021

cc @odeke-em

@cuonglm
Copy link
Contributor Author

cuonglm commented Apr 28, 2021

cc @AmauryM

@codecov
Copy link

codecov bot commented Apr 28, 2021

Codecov Report

Merging #9223 (662e20f) into master (0cbed20) will increase coverage by 0.08%.
The diff coverage is 81.81%.

❗ Current head 662e20f differs from pull request most recent head 61efc13. Consider uploading reports for the commit 61efc13 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9223      +/-   ##
==========================================
+ Coverage   59.95%   60.03%   +0.08%     
==========================================
  Files         595      595              
  Lines       37357    37352       -5     
==========================================
+ Hits        22397    22425      +28     
+ Misses      12974    12939      -35     
- Partials     1986     1988       +2     
Impacted Files Coverage Δ
x/feegrant/keeper/keeper.go 85.05% <80.64%> (+7.88%) ⬆️
x/feegrant/client/testutil/suite.go 99.66% <100.00%> (ø)
x/feegrant/keeper/msg_server.go 86.20% <100.00%> (+79.31%) ⬆️
x/feegrant/types/expiration.go 82.00% <0.00%> (+4.00%) ⬆️

Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

thanks!

Copy link
Collaborator

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

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

Thank you @cuonglm, LGTM but we can simplify this code more.

x/gov/keeper/querier_test.go Outdated Show resolved Hide resolved
When testing with -race, sometimes the random source generate the same
string for consecutive calls, causing duplicated voter address. So the
number of votes in DB is not 20.

To fix this, we ensure unique addresses are generated, by using a map
for tracking which one was produced, and skip the duplicated address and
generated new one. Testing with:

	go test -race -v -count=1000 -run=TestPaginatedVotesQuery

now passes.

Updates #9010
@cuonglm cuonglm requested a review from odeke-em April 28, 2021 16:53
Copy link
Collaborator

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

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

LGTM, thank you Cuong!

@amaury1093 amaury1093 added the A:automerge Automatically merge PR once all prerequisites pass. label Apr 28, 2021
@mergify mergify bot merged commit 6ad84c5 into cosmos:master Apr 28, 2021
mergify bot pushed a commit that referenced this pull request Apr 28, 2021
When testing with -race, sometimes the random source generate the same
string for consecutive calls, causing duplicated voter address. So the
number of votes in DB is not 20.

To fix this, we ensure unique addresses are generated, by using a map
for tracking which one was produced, and skip the duplicated address and
generated new one. Testing with:

	go test -race -v -count=1000 -run=TestPaginatedVotesQuery

now passes.

Updates #9010

(cherry picked from commit 6ad84c5)

# Conflicts:
#	x/gov/keeper/querier_test.go
@amaury1093 amaury1093 mentioned this pull request Apr 29, 2021
17 tasks
amaury1093 added a commit that referenced this pull request Apr 29, 2021
* x/gov/keeper: fix flaky TestPaginatedVotesQuery (#9223)

When testing with -race, sometimes the random source generate the same
string for consecutive calls, causing duplicated voter address. So the
number of votes in DB is not 20.

To fix this, we ensure unique addresses are generated, by using a map
for tracking which one was produced, and skip the duplicated address and
generated new one. Testing with:

	go test -race -v -count=1000 -run=TestPaginatedVotesQuery

now passes.

Updates #9010

(cherry picked from commit 6ad84c5)

# Conflicts:
#	x/gov/keeper/querier_test.go

* fi merge conflict

Co-authored-by: Cuong Manh Le <cuong@orijtech.com>
Co-authored-by: Amaury M <1293565+amaurym@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. C:x/gov
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants