-
Notifications
You must be signed in to change notification settings - Fork 166
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
Kan/clean up secondary result index #1515
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
85765cf
Remove from secondary index
Kay-Zee 479edf4
Add tests for caches
Kay-Zee 2bbbd35
add concurrency test
zhangchiqing 4d32b0b
Merge branch 'master' into kan/clean-up-secondary-result-index
zhangchiqing 2545d95
Merge branch 'master' into kan/clean-up-secondary-result-index
zhangchiqing 4885eb5
Merge branch 'master' into kan/clean-up-secondary-result-index
zhangchiqing c4e4e88
Apply suggestions from code review
zhangchiqing File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package approvals | ||
|
||
import ( | ||
"sync" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/onflow/flow-go/model/flow" | ||
"github.com/onflow/flow-go/utils/unittest" | ||
) | ||
|
||
// TestApprovalsCache_Get_Put_All tests common use cases for approvals cache. | ||
func TestApprovalsLRUCacheSecondaryIndexPurge(t *testing.T) { | ||
numElements := uint(10) | ||
cache := NewApprovalsLRUCache(numElements) | ||
approvals := make([]*flow.ResultApproval, 2*numElements) | ||
for i := range approvals { | ||
approval := unittest.ResultApprovalFixture() | ||
approvals[i] = approval | ||
cache.Put(approval) | ||
require.Equal(t, approval, cache.Get(approval.Body.PartialID())) | ||
} | ||
|
||
// LRU kept the last 10 approvals | ||
for i := 10; i < 20; i++ { | ||
approval := approvals[i] | ||
require.Equal(t, approval, cache.Get(approval.Body.PartialID())) | ||
} | ||
require.Len(t, cache.byResultID, int(numElements)) | ||
} | ||
|
||
func TestApprovalsLRUCacheSecondaryIndexPurgeConcurrently(t *testing.T) { | ||
numElements := 100 | ||
cache := NewApprovalsLRUCache(uint(numElements)) | ||
|
||
var wg sync.WaitGroup | ||
|
||
for i := 0; i < 2*numElements; i++ { | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
approval := unittest.ResultApprovalFixture() | ||
cache.Put(approval) | ||
}() | ||
} | ||
wg.Wait() | ||
require.Len(t, cache.byResultID, int(numElements)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,26 +11,30 @@ import ( | |
|
||
// TestApprovalsCache_Get_Put_All tests common use cases for approvals cache. | ||
func TestApprovalsCache_Get_Put_All(t *testing.T) { | ||
cache := NewApprovalsCache(10) | ||
approvals := make([]*flow.ResultApproval, 0, 10) | ||
numElements := uint(10) | ||
cache := NewApprovalsCache(numElements) | ||
approvals := make([]*flow.ResultApproval, numElements) | ||
for i := range approvals { | ||
approval := unittest.ResultApprovalFixture() | ||
approvals[i] = approval | ||
require.True(t, cache.Put(approval.Body.PartialID(), approval)) | ||
require.Equal(t, approval, cache.Get(approval.Body.PartialID())) | ||
} | ||
require.ElementsMatch(t, approvals, cache.All()) | ||
require.Len(t, cache.All(), int(numElements)) | ||
} | ||
|
||
// TestIncorporatedResultsCache_Get_Put_All tests common use cases for incorporated results cache. | ||
func TestIncorporatedResultsCache_Get_Put_All(t *testing.T) { | ||
cache := NewIncorporatedResultsCache(10) | ||
results := make([]*flow.IncorporatedResult, 0, 10) | ||
numElements := uint(10) | ||
cache := NewIncorporatedResultsCache(numElements) | ||
results := make([]*flow.IncorporatedResult, numElements) | ||
for i := range results { | ||
result := unittest.IncorporatedResult.Fixture() | ||
results[i] = result | ||
require.True(t, cache.Put(result.ID(), result)) | ||
require.Equal(t, result, cache.Get(result.ID())) | ||
} | ||
require.ElementsMatch(t, results, cache.All()) | ||
require.Equal(t, int(numElements), len(cache.All())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comments here as above. |
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It seems this
approvals
field isn't really necessary? We don't actually do anything with the approvals we store inside.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.
Maybe you actually meant to add a check?