Skip to content

Commit

Permalink
Automated rollback of commit af580b4.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 655641669
  • Loading branch information
ananda1066 authored and copybara-github committed Jul 24, 2024
1 parent 27e5761 commit c02437a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 32 deletions.
5 changes: 2 additions & 3 deletions src/core/lib/resource_quota/periodic_update.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ bool PeriodicUpdate::MaybeEndPeriod(absl::FunctionRef<void(Duration)> 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;
}
Expand Down
30 changes: 1 addition & 29 deletions test/core/resource_quota/periodic_update_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<PeriodicUpdate> upd;
std::atomic<int> count(0);
Timestamp start;
Expand Down

0 comments on commit c02437a

Please sign in to comment.