| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/task_scheduler/scheduler_worker_thread_stack.h" | 5 #include "base/task_scheduler/scheduler_worker_thread_stack.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/task_scheduler/scheduler_worker_thread.h" | 10 #include "base/task_scheduler/scheduler_worker_thread.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 return nullptr; | 29 return nullptr; |
| 30 } | 30 } |
| 31 void ReEnqueueSequence(scoped_refptr<Sequence> sequence) override { | 31 void ReEnqueueSequence(scoped_refptr<Sequence> sequence) override { |
| 32 ADD_FAILURE() << "This delegate not expect to have sequences to reenqueue."; | 32 ADD_FAILURE() << "This delegate not expect to have sequences to reenqueue."; |
| 33 } | 33 } |
| 34 TimeDelta GetSleepTimeout() override { | 34 TimeDelta GetSleepTimeout() override { |
| 35 ADD_FAILURE() << | 35 ADD_FAILURE() << |
| 36 "The mock thread is not expected to be woken before it is shutdown"; | 36 "The mock thread is not expected to be woken before it is shutdown"; |
| 37 return TimeDelta::Max(); | 37 return TimeDelta::Max(); |
| 38 } | 38 } |
| 39 bool CanDetach(SchedulerWorkerThread* worker_thread) override { |
| 40 return false; |
| 41 } |
| 39 }; | 42 }; |
| 40 | 43 |
| 41 class TaskSchedulerWorkerThreadStackTest : public testing::Test { | 44 class TaskSchedulerWorkerThreadStackTest : public testing::Test { |
| 42 protected: | 45 protected: |
| 43 void SetUp() override { | 46 void SetUp() override { |
| 44 thread_a_ = SchedulerWorkerThread::Create( | 47 thread_a_ = SchedulerWorkerThread::Create( |
| 45 ThreadPriority::NORMAL, | 48 ThreadPriority::NORMAL, |
| 46 WrapUnique(new MockSchedulerWorkerThreadDelegate), &task_tracker_); | 49 WrapUnique(new MockSchedulerWorkerThreadDelegate), &task_tracker_, |
| 50 SchedulerWorkerThread::InitialWorkerState::ALIVE); |
| 47 ASSERT_TRUE(thread_a_); | 51 ASSERT_TRUE(thread_a_); |
| 48 thread_b_ = SchedulerWorkerThread::Create( | 52 thread_b_ = SchedulerWorkerThread::Create( |
| 49 ThreadPriority::NORMAL, | 53 ThreadPriority::NORMAL, |
| 50 WrapUnique(new MockSchedulerWorkerThreadDelegate), &task_tracker_); | 54 WrapUnique(new MockSchedulerWorkerThreadDelegate), &task_tracker_, |
| 55 SchedulerWorkerThread::InitialWorkerState::ALIVE); |
| 51 ASSERT_TRUE(thread_b_); | 56 ASSERT_TRUE(thread_b_); |
| 52 thread_c_ = SchedulerWorkerThread::Create( | 57 thread_c_ = SchedulerWorkerThread::Create( |
| 53 ThreadPriority::NORMAL, | 58 ThreadPriority::NORMAL, |
| 54 WrapUnique(new MockSchedulerWorkerThreadDelegate), &task_tracker_); | 59 WrapUnique(new MockSchedulerWorkerThreadDelegate), &task_tracker_, |
| 60 SchedulerWorkerThread::InitialWorkerState::ALIVE); |
| 55 ASSERT_TRUE(thread_c_); | 61 ASSERT_TRUE(thread_c_); |
| 56 } | 62 } |
| 57 | 63 |
| 58 void TearDown() override { | 64 void TearDown() override { |
| 59 thread_a_->JoinForTesting(); | 65 thread_a_->JoinForTesting(); |
| 60 thread_b_->JoinForTesting(); | 66 thread_b_->JoinForTesting(); |
| 61 thread_c_->JoinForTesting(); | 67 thread_c_->JoinForTesting(); |
| 62 } | 68 } |
| 63 | 69 |
| 64 std::unique_ptr<SchedulerWorkerThread> thread_a_; | 70 std::unique_ptr<SchedulerWorkerThread> thread_a_; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 168 |
| 163 // Verify that Push() DCHECKs when a value is inserted twice. | 169 // Verify that Push() DCHECKs when a value is inserted twice. |
| 164 TEST_F(TaskSchedulerWorkerThreadStackTest, PushTwice) { | 170 TEST_F(TaskSchedulerWorkerThreadStackTest, PushTwice) { |
| 165 SchedulerWorkerThreadStack stack; | 171 SchedulerWorkerThreadStack stack; |
| 166 stack.Push(thread_a_.get()); | 172 stack.Push(thread_a_.get()); |
| 167 EXPECT_DCHECK_DEATH({ stack.Push(thread_a_.get()); }, ""); | 173 EXPECT_DCHECK_DEATH({ stack.Push(thread_a_.get()); }, ""); |
| 168 } | 174 } |
| 169 | 175 |
| 170 } // namespace internal | 176 } // namespace internal |
| 171 } // namespace base | 177 } // namespace base |
| OLD | NEW |