diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-02-05 18:31:49 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-02-05 18:33:55 +0000 |
commit | 8b0e808c0cf605ffaf79300865294c0911663bd1 (patch) | |
tree | 7466f880e8d1916aefc4c9128153ed1d47b2e40f | |
parent | 9813f9cb0bcd7dfa039c33aa0f3b4b600d6fd8a9 (diff) |
Reduce use of getTimeInSeconds
-rw-r--r-- | storage/src/tests/common/metricstest.cpp | 22 | ||||
-rw-r--r-- | storage/src/tests/storageserver/statereportertest.cpp | 12 |
2 files changed, 16 insertions, 18 deletions
diff --git a/storage/src/tests/common/metricstest.cpp b/storage/src/tests/common/metricstest.cpp index a92cf121fab..5c0f951efda 100644 --- a/storage/src/tests/common/metricstest.cpp +++ b/storage/src/tests/common/metricstest.cpp @@ -37,10 +37,10 @@ struct MetricsTest : public Test { std::shared_ptr<BucketManagerMetrics> _bucketManagerMetrics; std::shared_ptr<VisitorMetrics> _visitorMetrics; - void createSnapshotForPeriod(std::chrono::seconds secs); + void createSnapshotForPeriod(std::chrono::seconds secs) const; void assertMetricLastValue(const std::string& name, int interval, - uint64_t expected); + uint64_t expected) const; MetricsTest(); ~MetricsTest() override; @@ -55,8 +55,8 @@ namespace { { framework::Clock& _clock; explicit MetricClock(framework::Clock& c) : _clock(c) {} - time_t getTime() const override { return _clock.getTimeInSeconds().getTime(); } - time_t getTimeInMilliSecs() const override { return _clock.getTimeInMillis().getTime(); } + [[nodiscard]] time_t getTime() const override { return _clock.getTimeInSeconds().getTime(); } + time_t getTimeInMilliSecs() const override { return vespalib::count_ms(_clock.getMonotonicTime().time_since_epoch()); } }; } @@ -137,8 +137,8 @@ void MetricsTest::createFakeLoad() disk.queueSize.addValue(4 * n); disk.averageQueueWaitingTime.addValue(10 * n); disk.pendingMerges.addValue(4 * n); - for (uint32_t j=0; j<disk.threads.size(); ++j) { - FileStorThreadMetrics& thread(*disk.threads[j]); + for (auto & j : disk.threads) { + FileStorThreadMetrics& thread(*j); thread.operations.inc(120 * n); thread.failedOperations.inc(2 * n); @@ -180,8 +180,8 @@ void MetricsTest::createFakeLoad() thread.merge_handler_metrics.mergeAverageDataReceivedNeeded.addValue(0.8); } } - for (uint32_t i=0; i<_visitorMetrics->threads.size(); ++i) { - VisitorThreadMetrics& thread(*_visitorMetrics->threads[i]); + for (auto & i : _visitorMetrics->threads) { + VisitorThreadMetrics& thread(*i); thread.queueSize.addValue(2); thread.averageQueueWaitingTime.addValue(10); thread.averageVisitorLifeTime.addValue(1000); @@ -284,9 +284,7 @@ TEST_F(MetricsTest, html_metrics_report) { } void -MetricsTest::assertMetricLastValue(const std::string& name, - int interval, - uint64_t expected) +MetricsTest::assertMetricLastValue(const std::string& name, int interval, uint64_t expected) const { std::ostringstream path; path << "metrics?interval=" << interval @@ -305,7 +303,7 @@ MetricsTest::assertMetricLastValue(const std::string& name, using namespace std::chrono_literals; void -MetricsTest::createSnapshotForPeriod(std::chrono::seconds secs) +MetricsTest::createSnapshotForPeriod(std::chrono::seconds secs) const { _clock->addSecondsToTime(secs.count()); _metricManager->timeChangedNotification(); diff --git a/storage/src/tests/storageserver/statereportertest.cpp b/storage/src/tests/storageserver/statereportertest.cpp index 47d70cf436e..08355c105d5 100644 --- a/storage/src/tests/storageserver/statereportertest.cpp +++ b/storage/src/tests/storageserver/statereportertest.cpp @@ -25,8 +25,8 @@ namespace storage { class DummyApplicationGenerationFether : public ApplicationGenerationFetcher { public: - int64_t getGeneration() const override { return 1; } - std::string getComponentName() const override { return "component"; } + [[nodiscard]] int64_t getGeneration() const override { return 1; } + [[nodiscard]] std::string getComponentName() const override { return "component"; } }; struct StateReporterTest : Test { @@ -54,8 +54,8 @@ struct MetricClock : public metrics::MetricManager::Timer { framework::Clock& _clock; explicit MetricClock(framework::Clock& c) : _clock(c) {} - time_t getTime() const override { return _clock.getTimeInSeconds().getTime(); } - time_t getTimeInMilliSecs() const override { return _clock.getTimeInMillis().getTime(); } + [[nodiscard]] time_t getTime() const override { return _clock.getTimeInSeconds().getTime(); } + [[nodiscard]] time_t getTimeInMilliSecs() const override { return vespalib::count_ms(_clock.getSystemTime().time_since_epoch()); } }; } @@ -245,8 +245,8 @@ TEST_F(StateReporterTest, report_metrics) { "/state/v1/metrics?consumer=status" }; - for (int i = 0; i < pathCount; i++) { - framework::HttpUrlPath path(paths[i]); + for (auto & path_str : paths) { + framework::HttpUrlPath path(path_str); std::ostringstream ost; _stateReporter->reportStatus(ost, path); std::string jsonData = ost.str(); |