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

blockchain: Test & Check Memory Usage #2167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions blockchain/utxocache_test.go
Copy link
Contributor

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.

Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

It appears that there is a logical error in the condition if resultShoulBeTrue. This condition implies that the test should fail when the memory usage matches the expected size, which is the opposite of the intended behavior.

I recommend changing the condition to if !resultShoulBeTrue or if result != expectedSize, indicating that the test should fail when the memory usage does not match the expected size

Copy link
Contributor

Choose a reason for hiding this comment

The 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)
}
}