Fix sensor count not updating
When ReadingsParamaters are updated, sensor count may change. This
action should resize buffer and update value of "AppendLimit" property
in case it was not set by user.
Testing done:
-UTs passing
Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
Change-Id: I96486a808a3cce83c09936262304d0a1f55b3fd7
diff --git a/tests/src/test_report.cpp b/tests/src/test_report.cpp
index d05620b..ea3b4f8 100644
--- a/tests/src/test_report.cpp
+++ b/tests/src/test_report.cpp
@@ -109,6 +109,10 @@
metricMocks.emplace_back(std::make_shared<NiceMock<MetricMock>>());
ON_CALL(*metricMocks[i], dumpConfiguration())
.WillByDefault(Return(metricParameters[i]));
+ ON_CALL(*metricMocks[i], sensorCount())
+ .WillByDefault(Return(metricParameters[i]
+ .at_label<tstring::SensorPath>()
+ .size()));
}
return utils::convContainer<std::shared_ptr<interfaces::Metric>>(
@@ -281,6 +285,34 @@
Eq(newParams));
}
+TEST_F(TestReport, setReadingParametersWithNewParamsUpdatesSensorCount)
+{
+ auto report =
+ makeReport(ReportParams()
+ .appendLimit(std::numeric_limits<uint64_t>::max())
+ .reportId("DefaultAppendLimit"));
+
+ ReadingParameters newParams = toReadingParameters(
+ std::vector<LabeledMetricParameters>{{LabeledMetricParameters{
+ {LabeledSensorInfo{"Service",
+ "/xyz/openbmc_project/sensors/power/psu",
+ "NewMetadata123"}},
+ OperationType::avg,
+ "NewMetricId123",
+ CollectionTimeScope::startup,
+ CollectionDuration(250ms)}}});
+ auto metrics = getMetricsFromReadingParams(newParams);
+
+ EXPECT_CALL(*reportFactoryMock, updateMetrics(_, _, _))
+ .WillOnce(SetArgReferee<0>(metrics));
+ EXPECT_THAT(setProperty(report->getPath(), "ReadingParametersFutureVersion",
+ newParams)
+ .value(),
+ Eq(boost::system::errc::success));
+ EXPECT_THAT(getProperty<uint64_t>(report->getPath(), "AppendLimit"),
+ Eq(1ull));
+}
+
TEST_F(TestReport, setReadingParametersWithTooLongMetricId)
{
const ReadingParameters currentValue =