assert duration in callback (#30618)

pull/30653/head
AJ Heller 2 years ago committed by GitHub
parent 7712f93805
commit 8a466c209e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      test/core/resource_quota/periodic_update_test.cc

@ -35,6 +35,7 @@ namespace testing {
TEST(PeriodicUpdateTest, SimpleTest) {
std::unique_ptr<PeriodicUpdate> upd;
Timestamp start;
Timestamp reset_start;
// Create a periodic update that updates every second.
{
ExecCtx exec_ctx;
@ -45,20 +46,28 @@ TEST(PeriodicUpdateTest, SimpleTest) {
bool done = false;
while (!done) {
ExecCtx exec_ctx;
upd->Tick([&](Duration) { done = true; });
upd->Tick([&](Duration elapsed) {
reset_start = ExecCtx::Get()->Now();
EXPECT_GE(elapsed, Duration::Seconds(1));
done = true;
});
}
// Ensure that took at least 1 second.
{
ExecCtx exec_ctx;
EXPECT_GE(exec_ctx.Now() - start, Duration::Seconds(1));
start = exec_ctx.Now();
start = reset_start;
}
// Do ten more update cycles
for (int i = 0; i < 10; i++) {
done = false;
while (!done) {
ExecCtx exec_ctx;
upd->Tick([&](Duration) { done = true; });
upd->Tick([&](Duration elapsed) {
reset_start = ExecCtx::Get()->Now();
EXPECT_GE(exec_ctx.Now() - start, Duration::Seconds(1));
done = true;
});
}
// Ensure the time taken was between 1 and 3 seconds - we make a little
// allowance for the presumed inaccuracy of this type.
@ -66,7 +75,7 @@ TEST(PeriodicUpdateTest, SimpleTest) {
ExecCtx exec_ctx;
EXPECT_GE(exec_ctx.Now() - start, Duration::Seconds(1));
EXPECT_LE(exec_ctx.Now() - start, Duration::Seconds(3));
start = exec_ctx.Now();
start = reset_start;
}
}
}

Loading…
Cancel
Save