Add blocking call in BandwidthStatsTest destructor

task_queue_ outlives the BandwidthStatsTest object, but Posted task
captures |this|. Blocking call in the destructor is a simple way to avoid
that race
(should work as long as posted task doesn't call virtual functions from |this|).

Bug: webrtc:10933
Change-Id: Id30badb711480af5ee737b96b9224c1a73e730ee
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/158898
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29707}
This commit is contained in:
Danil Chapovalov 2019-11-06 13:28:11 +01:00 committed by Commit Bot
parent bd826152dd
commit 2f2049af23

View File

@ -91,6 +91,12 @@ class BandwidthStatsTest : public test::EndToEndTest {
send_side_bwe_(send_side_bwe),
task_queue_(task_queue) {}
~BandwidthStatsTest() override {
// Block until all already posted tasks run to avoid races when such task
// accesses |this|.
SendTask(RTC_FROM_HERE, task_queue_, [] {});
}
void ModifyVideoConfigs(
VideoSendStream::Config* send_config,
std::vector<VideoReceiveStream::Config>* receive_configs,
@ -197,7 +203,11 @@ TEST_F(BandwidthEndToEndTest, RembWithSendSideBwe) {
retransmission_rate_limiter_(clock_, 1000),
task_queue_(task_queue) {}
~BweObserver() {}
~BweObserver() override {
// Block until all already posted tasks run to avoid races when such task
// accesses |this|.
SendTask(RTC_FROM_HERE, task_queue_, [] {});
}
std::unique_ptr<test::PacketTransport> CreateReceiveTransport(
TaskQueueBase* task_queue) override {