| 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 14 matching lines...) Expand all Loading... |
| 25 public: | 25 public: |
| 26 void OnMainEntry(SchedulerWorkerThread* worker_thread) override {} | 26 void OnMainEntry(SchedulerWorkerThread* worker_thread) override {} |
| 27 scoped_refptr<Sequence> GetWork( | 27 scoped_refptr<Sequence> GetWork( |
| 28 SchedulerWorkerThread* worker_thread) override { | 28 SchedulerWorkerThread* worker_thread) override { |
| 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() << | |
| 36 "The mock thread is not expected to be woken before it is shutdown"; | |
| 37 return TimeDelta::Max(); | 35 return TimeDelta::Max(); |
| 38 } | 36 } |
| 37 bool CanDetach(SchedulerWorkerThread* worker_thread) override { |
| 38 return false; |
| 39 } |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 class TaskSchedulerWorkerThreadStackTest : public testing::Test { | 42 class TaskSchedulerWorkerThreadStackTest : public testing::Test { |
| 42 protected: | 43 protected: |
| 43 void SetUp() override { | 44 void SetUp() override { |
| 44 thread_a_ = SchedulerWorkerThread::Create( | 45 thread_a_ = SchedulerWorkerThread::Create( |
| 45 ThreadPriority::NORMAL, | 46 ThreadPriority::NORMAL, |
| 46 WrapUnique(new MockSchedulerWorkerThreadDelegate), &task_tracker_); | 47 WrapUnique(new MockSchedulerWorkerThreadDelegate), &task_tracker_, |
| 48 SchedulerWorkerThread::InitialWorkerState::ALIVE); |
| 47 ASSERT_TRUE(thread_a_); | 49 ASSERT_TRUE(thread_a_); |
| 48 thread_b_ = SchedulerWorkerThread::Create( | 50 thread_b_ = SchedulerWorkerThread::Create( |
| 49 ThreadPriority::NORMAL, | 51 ThreadPriority::NORMAL, |
| 50 WrapUnique(new MockSchedulerWorkerThreadDelegate), &task_tracker_); | 52 WrapUnique(new MockSchedulerWorkerThreadDelegate), &task_tracker_, |
| 53 SchedulerWorkerThread::InitialWorkerState::ALIVE); |
| 51 ASSERT_TRUE(thread_b_); | 54 ASSERT_TRUE(thread_b_); |
| 52 thread_c_ = SchedulerWorkerThread::Create( | 55 thread_c_ = SchedulerWorkerThread::Create( |
| 53 ThreadPriority::NORMAL, | 56 ThreadPriority::NORMAL, |
| 54 WrapUnique(new MockSchedulerWorkerThreadDelegate), &task_tracker_); | 57 WrapUnique(new MockSchedulerWorkerThreadDelegate), &task_tracker_, |
| 58 SchedulerWorkerThread::InitialWorkerState::ALIVE); |
| 55 ASSERT_TRUE(thread_c_); | 59 ASSERT_TRUE(thread_c_); |
| 56 } | 60 } |
| 57 | 61 |
| 58 void TearDown() override { | 62 void TearDown() override { |
| 59 thread_a_->JoinForTesting(); | 63 thread_a_->JoinForTesting(); |
| 60 thread_b_->JoinForTesting(); | 64 thread_b_->JoinForTesting(); |
| 61 thread_c_->JoinForTesting(); | 65 thread_c_->JoinForTesting(); |
| 62 } | 66 } |
| 63 | 67 |
| 64 std::unique_ptr<SchedulerWorkerThread> thread_a_; | 68 std::unique_ptr<SchedulerWorkerThread> thread_a_; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 166 |
| 163 // Verify that Push() DCHECKs when a value is inserted twice. | 167 // Verify that Push() DCHECKs when a value is inserted twice. |
| 164 TEST_F(TaskSchedulerWorkerThreadStackTest, PushTwice) { | 168 TEST_F(TaskSchedulerWorkerThreadStackTest, PushTwice) { |
| 165 SchedulerWorkerThreadStack stack; | 169 SchedulerWorkerThreadStack stack; |
| 166 stack.Push(thread_a_.get()); | 170 stack.Push(thread_a_.get()); |
| 167 EXPECT_DCHECK_DEATH({ stack.Push(thread_a_.get()); }, ""); | 171 EXPECT_DCHECK_DEATH({ stack.Push(thread_a_.get()); }, ""); |
| 168 } | 172 } |
| 169 | 173 |
| 170 } // namespace internal | 174 } // namespace internal |
| 171 } // namespace base | 175 } // namespace base |
| OLD | NEW |