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

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, 11 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
Index: base/test/task_runner_test_template.h
===================================================================
--- base/test/task_runner_test_template.h (revision 178148)
+++ base/test/task_runner_test_template.h (working copy)
@@ -58,6 +58,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 +82,8 @@
std::map<int, int> GetTaskRunCounts() const;
+ void WaitForTasksToComplete(int count);
jar (doing other things) 2013/02/22 23:39:47 nit: same rename as other template.
+
private:
friend class RefCountedThreadSafe<TaskTracker>;
@@ -88,8 +91,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 +145,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 +156,10 @@
task_runner->PostDelayedTask(
FROM_HERE, ith_task, base::TimeDelta::FromMilliseconds(j));
++expected_task_run_counts[i];
+ ++expected_total_tasks;
}
}
+ this->task_tracker_->WaitForTasksToComplete(expected_total_tasks);
this->delegate_.StopTaskRunner();
EXPECT_EQ(expected_task_run_counts,

Powered by Google App Engine
This is Rietveld 408576698