-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
blockchain: Test & Check Memory Usage #2167
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -960,3 +960,20 @@ func TestInitConsistentState(t *testing.T) { | |
blocks[len(blocks)-1].Height()) | ||
} | ||
} | ||
|
||
func TestTotalMemoryUsage(t *testing.T) { | ||
// Mocked utxoCache instance | ||
s := newUtxoCache(nil, 1*1024*1024) | ||
|
||
// Call the totalMemoryUsage method | ||
result := s.totalMemoryUsage() | ||
|
||
expectedSize := uint64(1 * 1024 * 1024) | ||
|
||
resultShoulBeTrue := result == expectedSize | ||
|
||
// Compare the expected result with the actual result | ||
if resultShoulBeTrue { | ||
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. It appears that there is a logical error in the condition I recommend changing the condition to 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. Additionally, it's important to note that totalMemoryUsage and maxTotalMemoryUsage represent different concepts. maxTotalMemoryUsage is the maximum memory usage allowed for the cache in normal circumstances, while totalMemoryUsage is the map size + the size that the utxo entries are taking up. |
||
t.Errorf("Expected memory usage %d, got %d", expectedSize, result) | ||
} | ||
} |
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.
Overall, thank you for your contribution to the project and for your efforts in writing tests.