From 8a466c209e229675ef3856f920285a49b6e5791b Mon Sep 17 00:00:00 2001 From: AJ Heller Date: Wed, 17 Aug 2022 15:17:45 -0700 Subject: [PATCH] assert duration in callback (#30618) --- .../core/resource_quota/periodic_update_test.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/test/core/resource_quota/periodic_update_test.cc b/test/core/resource_quota/periodic_update_test.cc index c2afd93e278..003c70303e9 100644 --- a/test/core/resource_quota/periodic_update_test.cc +++ b/test/core/resource_quota/periodic_update_test.cc @@ -35,6 +35,7 @@ namespace testing { TEST(PeriodicUpdateTest, SimpleTest) { std::unique_ptr 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; } } }