pull/36932/head
Craig Tiller 5 months ago
parent ba41f5a63f
commit c3b612a995
  1. 30
      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<PeriodicUpdate> upd;
std::atomic<int> count(0);
Timestamp start;

Loading…
Cancel
Save