From c02437a92f44d1aa69d6dfc3fa9f6e4ce1eaa151 Mon Sep 17 00:00:00 2001 From: Alisha Nanda Date: Wed, 24 Jul 2024 11:33:19 -0700 Subject: [PATCH] Automated rollback of commit af580b4422852269ee7cfa6369f498772d3c88fb. PiperOrigin-RevId: 655641669 --- .../lib/resource_quota/periodic_update.cc | 5 ++-- .../resource_quota/periodic_update_test.cc | 30 +------------------ 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/src/core/lib/resource_quota/periodic_update.cc b/src/core/lib/resource_quota/periodic_update.cc index a722f2c568f..b4874fea1da 100644 --- a/src/core/lib/resource_quota/periodic_update.cc +++ b/src/core/lib/resource_quota/periodic_update.cc @@ -56,9 +56,8 @@ bool PeriodicUpdate::MaybeEndPeriod(absl::FunctionRef f) { // Store the remainder left. Note that updates_remaining_ may have been // decremented by another thread whilst we performed the above calculations: // we simply discard those decrements. - auto remaining = better_guess - expected_updates_per_period_; - expected_updates_per_period_ = better_guess; - updates_remaining_.store(remaining, std::memory_order_release); + updates_remaining_.store(better_guess - expected_updates_per_period_, + std::memory_order_release); // Not quite done, return, try for longer. return false; } diff --git a/test/core/resource_quota/periodic_update_test.cc b/test/core/resource_quota/periodic_update_test.cc index 0918575d971..90d98913693 100644 --- a/test/core/resource_quota/periodic_update_test.cc +++ b/test/core/resource_quota/periodic_update_test.cc @@ -78,35 +78,7 @@ TEST(PeriodicUpdateTest, SimpleTest) { } } -TEST(PeriodicUpdateTest, NoSpin) { - // Ensure that we do not poll the time every update... even initially - class NowCounter final : public Timestamp::ScopedSource { - public: - Timestamp Now() override { - ++n_; - return previous()->Now(); - } - - int now_calls() const { return n_; } - - private: - int n_ = 0; - }; - NowCounter counter; - PeriodicUpdate upd(Duration::Seconds(5)); - while (!upd.Tick([](Duration d) { EXPECT_GE(d, Duration::Seconds(5)); })) { - } - const int initial_now_calls = counter.now_calls(); - EXPECT_GT(initial_now_calls, 2); - EXPECT_LT(initial_now_calls, 100); - while (!upd.Tick([](Duration d) { EXPECT_GE(d, Duration::Seconds(5)); })) { - } - const int second_round_calls = counter.now_calls() - initial_now_calls; - EXPECT_GE(second_round_calls, 1); - EXPECT_LE(second_round_calls, initial_now_calls); -} - -TEST(PeriodicUpdateTest, ThreadTest) { +TEST(PeriodicUpdate, ThreadTest) { std::unique_ptr upd; std::atomic count(0); Timestamp start;