chenBright commented on code in PR #3773:
URL: https://github.com/apache/brpc/pull/3773#discussion_r4729835762
##########
src/brpc/socket.cpp:
##########
@@ -2418,7 +2418,7 @@ void Socket::DebugSocket(std::ostream& os, SocketId id) {
<< "\nnevent=" << ptr->_nevent.load(butil::memory_order_relaxed)
<< "\nfd=" << fd
<< "\ntos=" << ptr->_tos
- << "\nreset_fd_to_now=" << butil::cpuwide_time_us() -
ptr->_reset_fd_real_us << "us"
+ << "\nreset_fd_to_now=" << butil::gettimeofday_us() -
ptr->_reset_fd_real_us << "us"
Review Comment:
`reset_fd_to_now` indicates how much time has elapsed since the last fd
reset. After switching to wall-clock subtraction here, if the system clock is
set back 60 seconds 5 seconds after the reset, `/sockets` will show
approximately `-55000000us`.
##########
test/brpc_builtin_service_unittest.cpp:
##########
@@ -171,6 +172,26 @@ void CheckTraceId(const brpc::Controller& cntl,
ASSERT_TRUE(pos != std::string::npos) << expect_str;
}
+void CheckCreatedTimeNearNow(const brpc::Controller& cntl) {
+ const std::string& content = cntl.response_attachment().to_string();
+ const std::size_t header = content.find("CreatedTime");
+ ASSERT_NE(std::string::npos, header) << content;
+ const std::size_t header_end = content.find('\n', header);
+ ASSERT_NE(std::string::npos, header_end) << content;
+ const std::size_t col_end = content.find('|', header_end);
+ ASSERT_NE(std::string::npos, col_end) << content;
+ const std::string created =
+ content.substr(header_end + 1, col_end - header_end - 1);
+
+ const int64_t now_us = butil::gettimeofday_us();
+ std::ostringstream lower;
+ std::ostringstream upper;
+ brpc::PrintRealDateTime(lower, now_us - 600 * 1000000L);
+ brpc::PrintRealDateTime(upper, now_us + 600 * 1000000L);
+ ASSERT_GE(created, lower.str()) << "CreatedTime=" << created;
+ ASSERT_LE(created, upper.str()) << "CreatedTime=" << created;
Review Comment:
Lexicographic comparison will still fail at the daylight saving time
fall-back transition. For example, if the current time is `01:55` before the
transition, the formatted times 10 minutes before and after are `01:45` and
`01:05` after the clock is set back, respectively, so the lower bound is
already greater than the upper bound.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]