-
Notifications
You must be signed in to change notification settings - Fork 215
Extended the search for the full history resolver #5544
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b7bf797
- extended the search for the full history resolver in case the epoch…
iulianpascalau 0739bad
- changed test description
iulianpascalau a433338
Merge branch 'rc/v1.6.0' into extend-full-history-resolver-search
iulianpascalau 210e4f0
Merge branch 'rc/v1.6.0' into extend-full-history-resolver-search
iulianpascalau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
101 changes: 101 additions & 0 deletions
101
dataRetriever/resolvers/baseFullHistoryResolver_test.go
This file contains hidden or 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,101 @@ | ||
| package resolvers | ||
|
|
||
| import ( | ||
| "errors" | ||
| "testing" | ||
|
|
||
| "github.com/multiversx/mx-chain-go/testscommon/storage" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestBaseFullHistoryResolver_SearchFirst(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| testKey := []byte("key") | ||
| testValue := []byte("value") | ||
| resolver := &baseFullHistoryResolver{ | ||
| storer: &storage.StorerStub{ | ||
| SearchFirstCalled: func(key []byte) ([]byte, error) { | ||
| assert.Equal(t, testKey, key) | ||
|
|
||
| return testValue, nil | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| val, err := resolver.searchFirst(testKey) | ||
| assert.Nil(t, err) | ||
| assert.Equal(t, testValue, val) | ||
| } | ||
|
|
||
| func TestBaseFullHistoryResolver_GetFromStorage(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| testKey := []byte("key") | ||
| testValue := []byte("value") | ||
| testEpoch := uint32(37) | ||
|
|
||
| t.Run("get from epoch returned nil error and not empty buffer", func(t *testing.T) { | ||
| resolver := &baseFullHistoryResolver{ | ||
| storer: &storage.StorerStub{ | ||
| SearchFirstCalled: func(key []byte) ([]byte, error) { | ||
| assert.Fail(t, "should have not called SearchFirst") | ||
|
|
||
| return nil, nil | ||
| }, | ||
| GetFromEpochCalled: func(key []byte, epoch uint32) ([]byte, error) { | ||
| assert.Equal(t, testKey, key) | ||
| assert.Equal(t, testEpoch, epoch) | ||
|
|
||
| return testValue, nil | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| val, err := resolver.getFromStorage(testKey, testEpoch) | ||
| assert.Nil(t, err) | ||
| assert.Equal(t, testValue, val) | ||
| }) | ||
| t.Run("get from epoch returned nil error and nil buffer", func(t *testing.T) { | ||
| resolver := &baseFullHistoryResolver{ | ||
| storer: &storage.StorerStub{ | ||
| SearchFirstCalled: func(key []byte) ([]byte, error) { | ||
| assert.Fail(t, "should have not called SearchFirst") | ||
|
|
||
| return nil, nil | ||
| }, | ||
| GetFromEpochCalled: func(key []byte, epoch uint32) ([]byte, error) { | ||
| assert.Equal(t, testKey, key) | ||
| assert.Equal(t, testEpoch, epoch) | ||
|
|
||
| return nil, nil | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| val, err := resolver.getFromStorage(testKey, testEpoch) | ||
| assert.Nil(t, err) | ||
| assert.Equal(t, 0, len(val)) | ||
| }) | ||
| t.Run("get from epoch returned error will fallback to search first", func(t *testing.T) { | ||
| resolver := &baseFullHistoryResolver{ | ||
| storer: &storage.StorerStub{ | ||
| SearchFirstCalled: func(key []byte) ([]byte, error) { | ||
| assert.Equal(t, testKey, key) | ||
|
|
||
| return testValue, nil | ||
| }, | ||
| GetFromEpochCalled: func(key []byte, epoch uint32) ([]byte, error) { | ||
| assert.Equal(t, testKey, key) | ||
| assert.Equal(t, testEpoch, epoch) | ||
|
|
||
| return nil, errors.New("not found") | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| val, err := resolver.getFromStorage(testKey, testEpoch) | ||
| assert.Nil(t, err) | ||
| assert.Equal(t, testValue, val) | ||
| }) | ||
| } | ||
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.
Formatting / newline needed (and below).
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.
I generally prefer inner tests not separated by a new line. We should agree in a future clean code meeting if we will add empty lines or not in this particular case as to slowly align all existing code