blob: cdc576e52875964864ce15946039c72f7bf95346 [file] [log] [blame]
#include "monitoring.h"
#include "gmock.h"
#include "gunit.h"
#include "mock-log.h"
#include "absl/base/log_severity.h"
#include "absl/strings/string_view.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include <source_location>
#include "log_monitoring.h" // IWYU pragma: keep, Needed for template definitions
namespace {
using ::testing::HasSubstr;
using ::testing::ScopedMockLog;
TEST(LatencyMonitorTest, LatencyIsMeasuredCorrectly) {
ScopedMockLog log(testing::kDoNotCaptureLogsYet);
milotic::metrics::Latency<int> latency(
"test_latency", {"test_field"}, {.description = "Test latency metric"});
absl::Time now = absl::Now();
auto fake_now = [&now] { return now; };
EXPECT_CALL(
log, Log(base_logging::INFO, std::source_location::current().file_name(),
HasSubstr("test_latency(test_field=200): 1s")));
{
log.StartCapturingLogs();
milotic::LatencyMonitor monitor(&latency, {200}, fake_now);
now += absl::Seconds(1);
}
}
} // namespace