Skip to content

Commit ebb4a08

Browse files
BenHuddlestonrdemellow
authored andcommitted
MB-41868: [BP] Add test for histogram max size issue
Backport of commit ff44029. Add a test that we can still iterate histograms with more than int32_t max counts. Add a similar test to ensure that we can iterate with int64_t max counts too. Change-Id: I25813423c38fa0c1f5ead04377e952e43a9bc444 Reviewed-on: http://review.couchbase.org/c/kv_engine/+/137732 Well-Formed: Build Bot <[email protected]> Tested-by: Build Bot <[email protected]> Reviewed-by: Daniel Owen <[email protected]>
1 parent d589f50 commit ebb4a08

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

engines/ep/tests/module_tests/hdrhistogram_test.cc

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,70 @@ TEST(HdrHistogramTest, aggregationTestEmptyRhs) {
398398
EXPECT_EQ(0, histogramTwo.getValueCount());
399399
}
400400

401+
TEST(HdrHistogramTest, int32MaxSizeTest) {
402+
// Histogram type doesn't really matter for this but we first saw this with
403+
// a percentiles histogram so that's what we'll use here
404+
HdrHistogram histogram{
405+
0, 255, 1, HdrHistogram::Iterator::IterMode::Percentiles};
406+
407+
// Add int32_t max counts
408+
uint64_t limit = std::numeric_limits<int32_t>::max();
409+
histogram.addValueAndCount(0, limit);
410+
411+
// And test that returned values are correct
412+
EXPECT_EQ(limit, histogram.getValueCount());
413+
EXPECT_EQ(0, histogram.getValueAtPercentile(100.0));
414+
EXPECT_EQ(0, histogram.getMinValue());
415+
416+
HdrHistogram::Iterator iter{histogram.getHistogramsIterator()};
417+
auto res = histogram.getNextBucketLowHighAndCount(iter);
418+
EXPECT_TRUE(res);
419+
// The 3rd field [2] of the returned tuple is the count
420+
EXPECT_EQ(limit, std::get<2>(*res));
421+
422+
// Add 1 more count (previously this would overflow the total_count field
423+
// in the iterator)
424+
histogram.addValue(0);
425+
limit++;
426+
427+
// And test that returned values are correct
428+
EXPECT_EQ(limit, histogram.getValueCount());
429+
EXPECT_EQ(0, histogram.getValueAtPercentile(100.0));
430+
EXPECT_EQ(0, histogram.getMinValue());
431+
432+
HdrHistogram::Iterator iter2{histogram.getHistogramsIterator()};
433+
auto res2 = histogram.getNextBucketLowHighAndCount(iter2);
434+
EXPECT_TRUE(res2);
435+
// The 3rd field [2] of the returned tuple is the count
436+
EXPECT_EQ(limit, std::get<2>(*res2));
437+
}
438+
439+
TEST(HdrHistogramTest, int64MaxSizeTest) {
440+
// Histogram type doesn't really matter for this but we first saw this with
441+
// a percentiles histogram so that's what we'll use here
442+
HdrHistogram histogram{
443+
0, 255, 1, HdrHistogram::Iterator::IterMode::Percentiles};
444+
445+
// Add int64_t max counts
446+
uint64_t limit = std::numeric_limits<int64_t>::max();
447+
histogram.addValueAndCount(0, limit);
448+
449+
// And test that returned values are correct
450+
EXPECT_EQ(limit, histogram.getValueCount());
451+
EXPECT_EQ(0, histogram.getValueAtPercentile(100.0));
452+
EXPECT_EQ(0, histogram.getMinValue());
453+
454+
HdrHistogram::Iterator iter{histogram.getHistogramsIterator()};
455+
auto res = histogram.getNextBucketLowHighAndCount(iter);
456+
EXPECT_TRUE(res);
457+
// The 3rd field [2] of the returned tuple is the count
458+
EXPECT_EQ(limit, std::get<2>(*res));
459+
460+
// Testing any higher than this gives us garbage results back but
461+
// unfortunately with no way of knowing that they're garbage.
462+
}
463+
464+
401465
static std::vector<boost::optional<std::pair<uint64_t, double>>> getAllValues(
402466
const HdrHistogram& histo, HdrHistogram::Iterator& iter) {
403467
std::vector<boost::optional<std::pair<uint64_t, double>>> values;

0 commit comments

Comments
 (0)