Source release 16.4.0
This commit is contained in:
@@ -40,22 +40,28 @@ void TestHost::Reset() {
|
||||
}
|
||||
|
||||
void TestHost::ElapseTime(int64_t milliseconds) {
|
||||
// Note that, during the time rollback tests, milliseconds will be negative,
|
||||
// so we cannot assume goal_time > now_.
|
||||
int64_t goal_time = now_ + milliseconds;
|
||||
while (now_ < goal_time) {
|
||||
if (timers_.empty()) {
|
||||
now_ = goal_time;
|
||||
|
||||
// Walk forward from now_ to goal_time, stepping at each timer along the way
|
||||
// to fire its callback.
|
||||
while (!timers_.empty() && now_ < goal_time) {
|
||||
Timer t = timers_.top();
|
||||
ASSERT_GE(t.expiry_time(), now_);
|
||||
if (t.expiry_time() <= goal_time) {
|
||||
timers_.pop();
|
||||
now_ = t.expiry_time();
|
||||
t.client()->onTimerExpired(t.context());
|
||||
} else {
|
||||
Timer t = timers_.top();
|
||||
ASSERT_GE(t.expiry_time(), now_);
|
||||
if (t.expiry_time() <= goal_time) {
|
||||
timers_.pop();
|
||||
now_ = t.expiry_time();
|
||||
t.client()->onTimerExpired(t.context());
|
||||
} else {
|
||||
now_ = goal_time;
|
||||
}
|
||||
// The next timer is further in the future than goal_time, so we are done
|
||||
// processing the timers.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// No matter what happened with the timers, update now_ to the goal_time.
|
||||
now_ = goal_time;
|
||||
}
|
||||
|
||||
int TestHost::NumTimers() const { return timers_.size(); }
|
||||
|
||||
Reference in New Issue
Block a user