Make stopping of the RepeatingTask safer

Previous implementation assumes that though RepeatingTask is owned by
the task queue, it will stay alive until RepeatingTaskHandler stops it.
That assumption doesn't hold by one of downstream TaskQueue implementaions.
That TaskQueue implementation shortly before destruction deletes
pending delayed tasks because it doesn't plan to run them,
and then runs remaining regular tasks.

Bug: None
Change-Id: Ic95fec2e9961b3f05727ff6fbdaf0664434a995b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/221984
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34274}
This commit is contained in:
Danil Chapovalov
2021-06-11 18:39:17 +02:00
committed by WebRTC LUCI CQ
parent 4bb81aca75
commit 0f9a8e33c0
4 changed files with 66 additions and 62 deletions

View File

@ -276,4 +276,22 @@ TEST(RepeatingTaskTest, ClockIntegration) {
handle.Stop();
}
TEST(RepeatingTaskTest, CanBeStoppedAfterTaskQueueDeletedTheRepeatingTask) {
std::unique_ptr<QueuedTask> repeating_task;
MockTaskQueue task_queue;
EXPECT_CALL(task_queue, PostDelayedTask)
.WillOnce([&](std::unique_ptr<QueuedTask> task, uint32_t milliseconds) {
repeating_task = std::move(task);
});
RepeatingTaskHandle handle =
RepeatingTaskHandle::DelayedStart(&task_queue, TimeDelta::Millis(100),
[] { return TimeDelta::Millis(100); });
// shutdown task queue: delete all pending tasks and run 'regular' task.
repeating_task = nullptr;
handle.Stop();
}
} // namespace webrtc