Add special logging for infinite times (#29158)

pull/29160/head^2
Craig Tiller 3 years ago committed by GitHub
parent 99cbd49ef8
commit 364de4a8e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      src/core/lib/gprpp/time.cc
  2. 8
      test/core/gprpp/time_test.cc

@ -155,6 +155,12 @@ gpr_timespec Timestamp::as_timespec(gpr_clock_type clock_type) const {
}
std::string Timestamp::ToString() const {
if (millis_ == std::numeric_limits<int64_t>::max()) {
return "@∞";
}
if (millis_ == std::numeric_limits<int64_t>::min()) {
return "@-∞";
}
return "@" + std::to_string(millis_) + "ms";
}
@ -167,6 +173,12 @@ Duration Duration::FromTimespec(gpr_timespec t) {
}
std::string Duration::ToString() const {
if (millis_ == std::numeric_limits<int64_t>::max()) {
return "";
}
if (millis_ == std::numeric_limits<int64_t>::min()) {
return "-∞";
}
return std::to_string(millis_) + "ms";
}

@ -35,6 +35,8 @@ TEST(TimestampTest, Infinities) {
TEST(TimestampTest, ToString) {
EXPECT_EQ(Timestamp::FromMillisecondsAfterProcessEpoch(42).ToString(),
"@42ms");
EXPECT_EQ(Timestamp::InfFuture().ToString(), "@∞");
EXPECT_EQ(Timestamp::InfPast().ToString(), "@-∞");
}
TEST(DurationTest, Empty) { EXPECT_EQ(Duration(), Duration::Zero()); }
@ -78,6 +80,12 @@ TEST(DurationTest, FromTimespan) {
Duration::Milliseconds(1234));
}
TEST(DurationTest, ToString) {
EXPECT_EQ(Duration::Milliseconds(42).ToString(), "42ms");
EXPECT_EQ(Duration::Infinity().ToString(), "");
EXPECT_EQ(Duration::NegativeInfinity().ToString(), "-∞");
}
} // namespace testing
} // namespace grpc_core

Loading…
Cancel
Save