BewareMyPower opened a new pull request, #387:
URL: https://github.com/apache/pulsar-client-cpp/pull/387
### Motivation
`TimeUtils::currentTimeMillis()` is used to get the timestamp since 1970 but
`high_resolution_clock` does not necessarily represent the system clock. For
example, given the following code:
```c++
template <typename Clock>
inline int64_t getTimestamp() {
using namespace std::chrono;
return
duration_cast<milliseconds>(Clock::now().time_since_epoch()).count();
}
int main() {
std::cout << time(nullptr) << std::endl;
std::cout << getTimestamp<std::chrono::system_clock>() << std::endl;
std::cout << getTimestamp<std::chrono::high_resolution_clock>() <<
std::endl;
}
```
The outputs could be:
```
1705584279
1705584279351
38566832
```
### Modifications
Use `std::system_clock` for `currentTimeMillis()`. Add
`BackoffTest.testCurrentTimeMillis` to verify the result is similar to 1000
times of `time(nullptr)` (the timestamp in seconds from the C API).
--
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]