|
|
|
@ -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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|