[resource-quota] Fix periodic_update_test flake (#37691)

The timer wasn't taking into account the time for one update, which is necessary to get predictable behavior

Closes #37691

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/37691 from ctiller:flake-fightas-5 8fc8fb8398
PiperOrigin-RevId: 673731339
pull/37679/head
Craig Tiller 2 months ago committed by Copybara-Service
parent 037b04c7a7
commit 1f70b34fb1
  1. 8
      src/core/lib/gprpp/time.h
  2. 2
      src/core/lib/resource_quota/periodic_update.cc

@ -296,6 +296,14 @@ class Duration {
int64_t millis_; int64_t millis_;
}; };
inline std::ostream& operator<<(std::ostream& out, const Duration& d) {
return out << d.ToString();
}
inline std::ostream& operator<<(std::ostream& out, const Timestamp& d) {
return out << d.ToString();
}
inline Duration operator+(Duration lhs, Duration rhs) { inline Duration operator+(Duration lhs, Duration rhs) {
return Duration::Milliseconds( return Duration::Milliseconds(
time_detail::MillisAdd(lhs.millis(), rhs.millis())); time_detail::MillisAdd(lhs.millis(), rhs.millis()));

@ -68,8 +68,8 @@ bool PeriodicUpdate::MaybeEndPeriod(absl::FunctionRef<void(Duration)> f) {
expected_updates_per_period_ = expected_updates_per_period_ =
period_.seconds() * expected_updates_per_period_ / time_so_far.seconds(); period_.seconds() * expected_updates_per_period_ / time_so_far.seconds();
if (expected_updates_per_period_ < 1) expected_updates_per_period_ = 1; if (expected_updates_per_period_ < 1) expected_updates_per_period_ = 1;
period_start_ = now;
f(time_so_far); f(time_so_far);
period_start_ = Timestamp::Now();
updates_remaining_.store(expected_updates_per_period_, updates_remaining_.store(expected_updates_per_period_,
std::memory_order_release); std::memory_order_release);
return true; return true;

Loading…
Cancel
Save