diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
| commit | 4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch) | |
| tree | 1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/db/storage/key_string_test.cpp | |
| parent | aa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff) | |
| parent | 8f0827553e09872941945a093b647a4211a9db7f (diff) | |
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0'
with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/db/storage/key_string_test.cpp')
| -rw-r--r-- | src/mongo/db/storage/key_string_test.cpp | 30 |
1 files changed, 4 insertions, 26 deletions
diff --git a/src/mongo/db/storage/key_string_test.cpp b/src/mongo/db/storage/key_string_test.cpp index e1a29dcd8a1..ef9f7e744a5 100644 --- a/src/mongo/db/storage/key_string_test.cpp +++ b/src/mongo/db/storage/key_string_test.cpp @@ -283,18 +283,6 @@ TEST_F(KeyStringBuilderTest, MaxElementsInCompoundKey) { KeyString::getKeySize(ks.getBuffer(), ks.getSize(), ALL_ASCENDING, ks.getTypeBits()); } -TEST_F(KeyStringBuilderTest, EmbeddedNullString) { - // Construct a KeyString where \x3c defines the type kStringLike then embedded with null - // characters and followed by \x00. - const char* data = "\x3c\x00\xff\x00"; - const size_t size = 4; - KeyString::TypeBits typeBits(KeyString::Version::kLatestVersion); - - // No exceptions should be thrown. - ASSERT_BSONOBJ_EQ(KeyString::toBson(data, size, ALL_ASCENDING, typeBits), - BSON("" << StringData("\x00", 1))); -}; - TEST_F(KeyStringBuilderTest, ExceededBSONDepth) { KeyString::Builder ks(KeyString::Version::V1); @@ -758,7 +746,7 @@ TEST_F(KeyStringBuilderTest, InvalidInfinityDecimalV0) { TEST_F(KeyStringBuilderTest, ReasonableSize) { // Tests that KeyString::Builders do not use an excessive amount of memory for small key - // generation. These upper bounds were the calculated sizes of each type at the time this + // generation. These upper bounds were the calculate sizes of each type at the time this // test was written. KeyString::Builder stackBuilder(KeyString::Version::kLatestVersion, BSONObj(), ALL_ASCENDING); static_assert(sizeof(stackBuilder) <= 624); @@ -767,13 +755,8 @@ TEST_F(KeyStringBuilderTest, ReasonableSize) { KeyString::Version::kLatestVersion, BSONObj(), ALL_ASCENDING); static_assert(sizeof(heapBuilder) <= 104); - // Use a small block size to ensure we do not use more. Additionally, the minimum allocation - // size is 64. - const auto minSize = 64; - SharedBufferFragmentBuilder fragmentBuilder( - minSize, - SharedBufferFragmentBuilder::DoubleGrowStrategy( - SharedBufferFragmentBuilder::kDefaultMaxBlockSize)); + // Use large 1KB blocks and verify that we use way less + SharedBufferFragmentBuilder fragmentBuilder(1024); KeyString::PooledBuilder pooledBuilder( fragmentBuilder, KeyString::Version::kLatestVersion, BSONObj(), ALL_ASCENDING); static_assert(sizeof(pooledBuilder) <= 104); @@ -793,16 +776,11 @@ TEST_F(KeyStringBuilderTest, ReasonableSize) { KeyString::Value value4 = pooledBuilder.getValueCopy(); ASSERT_LTE(sizeof(value4), 32); - // This is safe because we are operating on a copy of the value and it is not shared elsewhere. ASSERT_LTE(value4.memUsageForSorter(), 34); - // We should still be using the initially-allocated size. - ASSERT_LTE(fragmentBuilder.memUsage(), 64); - // For values created with the pooledBuilder, it is invalid to call memUsageForSorter(). Instead - // we look at the mem usage of the builder itself. KeyString::Value value5 = pooledBuilder.release(); ASSERT_LTE(sizeof(value5), 32); - ASSERT_LTE(fragmentBuilder.memUsage(), 64); + ASSERT_LTE(value5.memUsageForSorter(), 34); } TEST_F(KeyStringBuilderTest, DiscardIfNotReleased) { |
