1
0
Fork 0
mirror of https://github.com/dragonflydb/dragonfly.git synced 2024-12-15 17:51:06 +00:00

chore: add a test for HeapSize() function (#3349)

This commit is contained in:
Roman Gershman 2024-07-23 19:02:57 +03:00 committed by GitHub
parent c8a98fd110
commit eba722b774
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,6 +10,7 @@
#include "absl/strings/str_cat.h"
#include "base/gtest.h"
#include "base/logging.h"
#include "core/heap_size.h"
#include "facade/facade_test.h"
using namespace testing;
@ -209,4 +210,24 @@ TEST_F(RedisParserTest, NestedArray) {
ASSERT_THAT(args_[1].GetVec(), ElementsAre("car"));
}
TEST_F(RedisParserTest, UsedMemory) {
vector<vector<uint8_t>> blobs;
for (size_t i = 0; i < 100; ++i) {
blobs.emplace_back(vector<uint8_t>(200));
}
EXPECT_GT(dfly::HeapSize(blobs), 20000);
std::vector<std::unique_ptr<RespVec>> stash;
RespVec vec;
for (unsigned i = 0; i < 10; ++i) {
vec.emplace_back(RespExpr::STRING);
vec.back().u = RespExpr::Buffer(nullptr, 0);
}
for (unsigned i = 0; i < 100; i++) {
stash.emplace_back(new RespExpr::Vec(vec));
}
EXPECT_GT(dfly::HeapSize(stash), 30000);
}
} // namespace facade