Chromium Code Reviews

Unified Diff: webrtc/logging/rtc_event_log/rtc_event_log_unittest.cc

Issue 3009763002: Prove TaskQueue issue
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
« no previous file with comments | « no previous file | webrtc/rtc_base/task_queue.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/logging/rtc_event_log/rtc_event_log_unittest.cc
diff --git a/webrtc/logging/rtc_event_log/rtc_event_log_unittest.cc b/webrtc/logging/rtc_event_log/rtc_event_log_unittest.cc
index e908ccd5fb1bdfb4ff93665119dac1d056acc438..d8b6f09ca8e0abe695c1e6304d961bd0c94f8f93 100644
--- a/webrtc/logging/rtc_event_log/rtc_event_log_unittest.cc
+++ b/webrtc/logging/rtc_event_log/rtc_event_log_unittest.cc
@@ -27,8 +27,11 @@
#include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h"
#include "webrtc/rtc_base/buffer.h"
#include "webrtc/rtc_base/checks.h"
+#include "webrtc/rtc_base/event.h"
#include "webrtc/rtc_base/fakeclock.h"
+#include "webrtc/rtc_base/ptr_util.h"
#include "webrtc/rtc_base/random.h"
+#include "webrtc/rtc_base/task_queue.h"
#include "webrtc/test/gtest.h"
#include "webrtc/test/testsupport/fileutils.h"
@@ -397,6 +400,61 @@ void LogSessionAndReadBack(size_t rtp_count,
remove(temp_filename.c_str());
}
+const char* const TAG = "GREP_ME";
+
+class BlockTask : public rtc::QueuedTask {
+ public:
+ explicit BlockTask(int wait_time_ms) : wait_time_ms_(wait_time_ms) {}
+
+ ~BlockTask() override {
+ printf("%s ~BlockTask()\n", TAG);
+ }
+
+ bool Run() override {
+ rtc::Event waiter(true, false);
+ printf("%s BlockTask: Waiting.\n", TAG);
+ waiter.Wait(wait_time_ms_);
+ printf("%s BlockTask: Wait complete.\n", TAG);
+ return true;
+ }
+
+ int wait_time_ms_;
+};
+
+class PrinterTask : public rtc::QueuedTask {
+ public:
+ explicit PrinterTask(size_t id) : id_(id) {}
+
+ ~PrinterTask() override {
+ printf("%s ~PrinterTask(%lu)\n", TAG, id_);
+ }
+
+ bool Run() override {
+ printf("%s PrinterTask(%lu)::Run()\n", TAG, id_);
+ return true;
+ }
+
+ size_t id_;
+};
+
+TEST(RandomLocationTest, ShowTaskQueueProblem) {
+ std::unique_ptr<rtc::TaskQueue> queue =
+ rtc::MakeUnique<rtc::TaskQueue>("queue");
+
+ // This task will block for a bit.
+ queue->PostTask(rtc::WrapUnique<rtc::QueuedTask>(new BlockTask(2000)));
+
+ // These tasks still get executed, despite the TaskQueue's destructor having
+ // been invoked while they were still pending.
+ for (int i = 0; i < 10; i++) {
+ queue->PostTask(rtc::WrapUnique<rtc::QueuedTask>(new PrinterTask(i)));
+ }
+
+ printf("%s About to invoke ~TaskQueue()\n", TAG);
+ queue.reset();
+ printf("%s ~TaskQueue() finished.\n", TAG);
+}
+
TEST(RtcEventLogTest, LogSessionAndReadBack) {
// Log 5 RTP, 2 RTCP, 0 playout events and 0 BWE events
// with no header extensions or CSRCS.
« no previous file with comments | « no previous file | webrtc/rtc_base/task_queue.h » ('j') | no next file with comments »

Powered by Google App Engine