Skip to content

Commit

Permalink
core: Add test for negative observed histogram value
Browse files Browse the repository at this point in the history
Fixes: #386
  • Loading branch information
gjasny committed Nov 1, 2020
1 parent efce85d commit 6d86e2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/include/prometheus/histogram.h
Expand Up @@ -4,9 +4,9 @@

#include "prometheus/client_metric.h"
#include "prometheus/counter.h"
#include "prometheus/gauge.h"
#include "prometheus/detail/builder.h"
#include "prometheus/detail/core_export.h"
#include "prometheus/gauge.h"
#include "prometheus/metric_type.h"

namespace prometheus {
Expand Down
8 changes: 8 additions & 0 deletions core/tests/histogram_test.cc
Expand Up @@ -108,5 +108,13 @@ TEST(HistogramTest, observe_multiple_test_length_error) {
ASSERT_THROW(histogram.ObserveMultiple({5, 9}, 20), std::length_error);
}

TEST(HistogramTest, sum_can_go_down) {
Histogram histogram{{1}};
auto metric1 = histogram.Collect();
histogram.Observe(-10);
auto metric2 = histogram.Collect();
EXPECT_LT(metric2.histogram.sample_sum, metric1.histogram.sample_sum);
}

} // namespace
} // namespace prometheus

0 comments on commit 6d86e2d

Please sign in to comment.