diff --git a/test/core/resource_quota/periodic_update_test.cc b/test/core/resource_quota/periodic_update_test.cc index 90d98913693..66b8fd7f1fa 100644 --- a/test/core/resource_quota/periodic_update_test.cc +++ b/test/core/resource_quota/periodic_update_test.cc @@ -78,7 +78,35 @@ TEST(PeriodicUpdateTest, SimpleTest) { } } -TEST(PeriodicUpdate, ThreadTest) { +TEST(PeriodicUpdateTest, NoSpin) { + // Ensure that we do not poll the time every update... even initially + class NowCounter : 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) { std::unique_ptr upd; std::atomic count(0); Timestamp start;