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

[test] using reserve and commit in watermark_buffer overflow high value test #12494

Merged
merged 6 commits into from
Aug 18, 2020
18 changes: 14 additions & 4 deletions test/common/buffer/watermark_buffer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -431,22 +431,32 @@ TEST_F(WatermarkBufferTest, OverflowWatermarkDisabledOnVeryHighValue) {

// Make sure the overflow threshold will be above std::numeric_limits<uint32_t>::max()
Runtime::LoaderSingleton::getExisting()->mergeValues({{"envoy.buffer.overflow_multiplier", "3"}});
buffer1.setWatermarks((std::numeric_limits<uint32_t>::max() / 3) + 1);
const uint32_t high_watermark_threshold = (std::numeric_limits<uint32_t>::max() / 3) + 1;
buffer1.setWatermarks(high_watermark_threshold);

// Add many segments instead of full uint32_t::max to get around std::bad_alloc exception
const uint32_t segment_denominator = 128;
const uint32_t big_segment_len = std::numeric_limits<uint32_t>::max() / segment_denominator + 1;
const std::string big_segment_str = std::string(big_segment_len, 'a');
// Fill the buffer with more than uint32_t::max bytes
EXPECT_GT(static_cast<uint64_t>(segment_denominator) * big_segment_len,
std::numeric_limits<uint32_t>::max());
adisuissa marked this conversation as resolved.
Show resolved Hide resolved
for (uint32_t i = 0; i < segment_denominator; ++i) {
buffer1.add(big_segment_str.data(), big_segment_len);
}
EXPECT_GT(buffer1.length(), std::numeric_limits<uint32_t>::max());
EXPECT_EQ(1, high_watermark_buffer1);
EXPECT_EQ(0, overflow_watermark_buffer1);
buffer1.add(TEN_BYTES, 10);
EXPECT_LT(buffer1.length(), high_watermark_threshold * UINT64_C(3));
adisuissa marked this conversation as resolved.
Show resolved Hide resolved
// Add more data to the buffer beyond the expected high_watermark_threshold*overflow_multiplier
// threshold. Adding high_watermark_threshold * UINT64_C(3) - buffer1.length() + 1 bytes
const std::string bytes_to_add(3, 'a');
buffer1.add(bytes_to_add.data(), bytes_to_add.size());
adisuissa marked this conversation as resolved.
Show resolved Hide resolved
EXPECT_EQ(buffer1.length(),
static_cast<uint64_t>(segment_denominator) * big_segment_len + bytes_to_add.size());
EXPECT_GT(buffer1.length(), high_watermark_threshold * UINT64_C(3));
EXPECT_EQ(1, high_watermark_buffer1);
EXPECT_EQ(0, overflow_watermark_buffer1);
EXPECT_EQ(static_cast<uint64_t>(segment_denominator) * big_segment_len + 10, buffer1.length());
EXPECT_GT(buffer1.length(), std::numeric_limits<uint32_t>::max());
#endif
}

Expand Down