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

Unified Diff: base/test/sequenced_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 | « no previous file | base/test/sequenced_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/sequenced_task_runner_test_template.h
===================================================================
--- base/test/sequenced_task_runner_test_template.h (revision 186525)
+++ base/test/sequenced_task_runner_test_template.h (working copy)
@@ -18,6 +18,7 @@
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/sequenced_task_runner.h"
+#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h"
#include "base/time.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -61,6 +62,9 @@
const std::vector<TaskEvent>& GetTaskEvents() const;
+ // Returns after the tracker observes a total of |count| task completions.
+ void WaitForCompletedTasks(int count);
+
private:
friend class RefCountedThreadSafe<SequencedTaskTracker>;
@@ -79,7 +83,7 @@
// Records a end event for task |i|.
void TaskEnded(int i);
- // Protects events_ and next_post_i_.
+ // Protects events_, next_post_i_, task_end_count_ and task_end_cv_.
Lock lock_;
// The events as they occurred for each task (protected by lock_).
@@ -89,6 +93,10 @@
// lock_).
int next_post_i_;
+ // The number of task end events we've received.
+ int task_end_count_;
+ ConditionVariable task_end_cv_;
+
DISALLOW_COPY_AND_ASSIGN(SequencedTaskTracker);
};
@@ -112,7 +120,7 @@
class SequencedTaskRunnerTest : public testing::Test {
protected:
SequencedTaskRunnerTest()
- : task_tracker_(new internal::SequencedTaskTracker()) {}
+ : task_tracker_(new internal::SequencedTaskTracker()) {}
const scoped_refptr<internal::SequencedTaskTracker> task_tracker_;
TaskRunnerTestDelegate delegate_;
@@ -191,6 +199,7 @@
TimeDelta::FromMilliseconds(kDelayIncrementMs * i));
}
+ this->task_tracker_->WaitForCompletedTasks(kTaskCount);
this->delegate_.StopTaskRunner();
EXPECT_TRUE(CheckNonNestableInvariants(this->task_tracker_->GetTaskEvents(),
@@ -244,6 +253,7 @@
Time time_before_run = Time::Now();
this->task_tracker_->PostWrappedDelayedNonNestableTask(
task_runner, Closure(), kDelay);
+ this->task_tracker_->WaitForCompletedTasks(kTaskCount);
this->delegate_.StopTaskRunner();
Time time_after_run = Time::Now();
@@ -278,6 +288,7 @@
task_runner, Closure(), kDelay);
this->task_tracker_->PostWrappedDelayedNonNestableTask(
task_runner, Closure(), kDelay);
+ this->task_tracker_->WaitForCompletedTasks(kTaskCount);
this->delegate_.StopTaskRunner();
EXPECT_TRUE(CheckNonNestableInvariants(this->task_tracker_->GetTaskEvents(),
@@ -306,6 +317,7 @@
TimeDelta::FromMilliseconds(50)));
this->task_tracker_->PostWrappedDelayedNonNestableTask(
task_runner, Closure(), TimeDelta::FromMilliseconds(10));
+ this->task_tracker_->WaitForCompletedTasks(kTaskCount);
this->delegate_.StopTaskRunner();
EXPECT_TRUE(CheckNonNestableInvariants(this->task_tracker_->GetTaskEvents(),
@@ -335,6 +347,7 @@
}
this->task_tracker_->PostWrappedDelayedNonNestableTask(
task_runner, Closure(), TimeDelta::FromMilliseconds(10));
+ this->task_tracker_->WaitForCompletedTasks(kTaskCount);
this->delegate_.StopTaskRunner();
EXPECT_TRUE(CheckNonNestableInvariants(this->task_tracker_->GetTaskEvents(),
« no previous file with comments | « no previous file | base/test/sequenced_task_runner_test_template.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698