Chromium Code Reviews| Index: base/test/sequenced_task_runner_test_template.h |
| =================================================================== |
| --- base/test/sequenced_task_runner_test_template.h (revision 183651) |
| +++ 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,8 @@ |
| const std::vector<TaskEvent>& GetTaskEvents() const; |
| + void WaitForCountTasksToComplete(int count); |
|
akalin
2013/02/26 00:12:23
There's a bit of an ambiguity here -- do you mean
michaeln
2013/02/27 00:57:12
Done.
|
| + |
| private: |
| friend class RefCountedThreadSafe<SequencedTaskTracker>; |
| @@ -79,7 +82,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 +92,10 @@ |
| // lock_). |
| int next_post_i_; |
| + // The number of task ends we've received. |
|
akalin
2013/02/26 00:12:23
task ends -> task end events
michaeln
2013/02/27 00:57:12
Done.
|
| + int task_end_count_; |
| + ConditionVariable task_end_cv_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(SequencedTaskTracker); |
| }; |
| @@ -112,7 +119,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 +198,7 @@ |
| TimeDelta::FromMilliseconds(kDelayIncrementMs * i)); |
| } |
| + this->task_tracker_->WaitForCountTasksToComplete(kTaskCount); |
| this->delegate_.StopTaskRunner(); |
| EXPECT_TRUE(CheckNonNestableInvariants(this->task_tracker_->GetTaskEvents(), |
| @@ -244,6 +252,7 @@ |
| Time time_before_run = Time::Now(); |
| this->task_tracker_->PostWrappedDelayedNonNestableTask( |
| task_runner, Closure(), kDelay); |
| + this->task_tracker_->WaitForCountTasksToComplete(1); |
|
akalin
2013/02/26 00:12:23
use kTaskCount here, too
michaeln
2013/02/27 00:57:12
Done.
|
| this->delegate_.StopTaskRunner(); |
| Time time_after_run = Time::Now(); |
| @@ -278,6 +287,7 @@ |
| task_runner, Closure(), kDelay); |
| this->task_tracker_->PostWrappedDelayedNonNestableTask( |
| task_runner, Closure(), kDelay); |
| + this->task_tracker_->WaitForCountTasksToComplete(kTaskCount); |
| this->delegate_.StopTaskRunner(); |
| EXPECT_TRUE(CheckNonNestableInvariants(this->task_tracker_->GetTaskEvents(), |
| @@ -306,6 +316,7 @@ |
| TimeDelta::FromMilliseconds(50))); |
| this->task_tracker_->PostWrappedDelayedNonNestableTask( |
| task_runner, Closure(), TimeDelta::FromMilliseconds(10)); |
| + this->task_tracker_->WaitForCountTasksToComplete(kTaskCount); |
| this->delegate_.StopTaskRunner(); |
| EXPECT_TRUE(CheckNonNestableInvariants(this->task_tracker_->GetTaskEvents(), |
| @@ -335,6 +346,7 @@ |
| } |
| this->task_tracker_->PostWrappedDelayedNonNestableTask( |
| task_runner, Closure(), TimeDelta::FromMilliseconds(10)); |
| + this->task_tracker_->WaitForCountTasksToComplete(kTaskCount); |
| this->delegate_.StopTaskRunner(); |
| EXPECT_TRUE(CheckNonNestableInvariants(this->task_tracker_->GetTaskEvents(), |