Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2140)

Unified Diff: base/test/task_runner_test_template.h

Issue 11649032: Flush SequenceWorkerPool tasks after each unit test. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/test/sequenced_task_runner_test_template.cc ('k') | base/test/task_runner_test_template.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/task_runner_test_template.h
===================================================================
--- base/test/task_runner_test_template.h (revision 186525)
+++ base/test/task_runner_test_template.h (working copy)
@@ -25,7 +25,8 @@
// }
//
// // Stop the task runner and make sure all tasks posted before
-// // this is called are run.
+// // this is called are run. Caveat: delayed tasks are not run,
+ // they're simply deleted.
// void StopTaskRunner() {
// ...
// }
@@ -58,6 +59,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/memory/ref_counted.h"
+#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h"
#include "base/task_runner.h"
#include "base/threading/thread.h"
@@ -81,6 +83,9 @@
std::map<int, int> GetTaskRunCounts() const;
+ // Returns after the tracker observes a total of |count| task completions.
+ void WaitForCompletedTasks(int count);
+
private:
friend class RefCountedThreadSafe<TaskTracker>;
@@ -88,8 +93,10 @@
void RunTask(const Closure& task, int i);
- mutable Lock task_run_counts_lock_;
+ mutable Lock lock_;
std::map<int, int> task_run_counts_;
+ int task_runs_;
+ ConditionVariable task_runs_cv_;
DISALLOW_COPY_AND_ASSIGN(TaskTracker);
};
@@ -140,6 +147,7 @@
}
std::map<int, int> expected_task_run_counts;
+ int expected_total_tasks = 0;
this->delegate_.StartTaskRunner();
scoped_refptr<TaskRunner> task_runner = this->delegate_.GetTaskRunner();
@@ -150,8 +158,10 @@
task_runner->PostDelayedTask(
FROM_HERE, ith_task, base::TimeDelta::FromMilliseconds(j));
++expected_task_run_counts[i];
+ ++expected_total_tasks;
}
}
+ this->task_tracker_->WaitForCompletedTasks(expected_total_tasks);
this->delegate_.StopTaskRunner();
EXPECT_EQ(expected_task_run_counts,
« no previous file with comments | « base/test/sequenced_task_runner_test_template.cc ('k') | base/test/task_runner_test_template.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698