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

Side by Side Diff: base/task_scheduler/task_tracker_unittest.cc

Issue 2032603002: Migrate WaitableEvent to enum-based constructor in base/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@WEvent_enums
Patch Set: undo incorrect template change Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « base/task_scheduler/task_scheduler_impl_unittest.cc ('k') | base/test/test_io_thread.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/task_tracker.h" 5 #include "base/task_scheduler/task_tracker.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 18 matching lines...) Expand all
29 namespace internal { 29 namespace internal {
30 30
31 namespace { 31 namespace {
32 32
33 // Calls TaskTracker::Shutdown() asynchronously. 33 // Calls TaskTracker::Shutdown() asynchronously.
34 class ThreadCallingShutdown : public SimpleThread { 34 class ThreadCallingShutdown : public SimpleThread {
35 public: 35 public:
36 explicit ThreadCallingShutdown(TaskTracker* tracker) 36 explicit ThreadCallingShutdown(TaskTracker* tracker)
37 : SimpleThread("ThreadCallingShutdown"), 37 : SimpleThread("ThreadCallingShutdown"),
38 tracker_(tracker), 38 tracker_(tracker),
39 has_returned_(true, false) {} 39 has_returned_(WaitableEvent::ResetPolicy::MANUAL,
40 WaitableEvent::InitialState::NOT_SIGNALED) {}
40 41
41 // Returns true once the async call to Shutdown() has returned. 42 // Returns true once the async call to Shutdown() has returned.
42 bool has_returned() { return has_returned_.IsSignaled(); } 43 bool has_returned() { return has_returned_.IsSignaled(); }
43 44
44 private: 45 private:
45 void Run() override { 46 void Run() override {
46 tracker_->Shutdown(); 47 tracker_->Shutdown();
47 has_returned_.Signal(); 48 has_returned_.Signal();
48 } 49 }
49 50
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 EXPECT_EQ(0U, num_tasks_executed_); 157 EXPECT_EQ(0U, num_tasks_executed_);
157 tracker_.RunTask(task.get()); 158 tracker_.RunTask(task.get());
158 EXPECT_EQ(1U, num_tasks_executed_); 159 EXPECT_EQ(1U, num_tasks_executed_);
159 160
160 // Shutdown() shouldn't block. 161 // Shutdown() shouldn't block.
161 tracker_.Shutdown(); 162 tracker_.Shutdown();
162 } 163 }
163 164
164 TEST_P(TaskSchedulerTaskTrackerTest, WillPostAndRunLongTaskBeforeShutdown) { 165 TEST_P(TaskSchedulerTaskTrackerTest, WillPostAndRunLongTaskBeforeShutdown) {
165 // Create a task that will block until |event| is signaled. 166 // Create a task that will block until |event| is signaled.
166 WaitableEvent event(false, false); 167 WaitableEvent event(WaitableEvent::ResetPolicy::AUTOMATIC,
168 WaitableEvent::InitialState::NOT_SIGNALED);
167 std::unique_ptr<Task> blocked_task( 169 std::unique_ptr<Task> blocked_task(
168 new Task(FROM_HERE, Bind(&WaitableEvent::Wait, Unretained(&event)), 170 new Task(FROM_HERE, Bind(&WaitableEvent::Wait, Unretained(&event)),
169 TaskTraits().WithShutdownBehavior(GetParam()), TimeDelta())); 171 TaskTraits().WithShutdownBehavior(GetParam()), TimeDelta()));
170 172
171 // Inform |task_tracker_| that |blocked_task| will be posted. 173 // Inform |task_tracker_| that |blocked_task| will be posted.
172 EXPECT_TRUE(tracker_.WillPostTask(blocked_task.get())); 174 EXPECT_TRUE(tracker_.WillPostTask(blocked_task.get()));
173 175
174 // Run the task asynchronouly. 176 // Run the task asynchronouly.
175 ThreadRunningTask thread_running_task(&tracker_, blocked_task.get()); 177 ThreadRunningTask thread_running_task(&tracker_, blocked_task.get());
176 thread_running_task.Start(); 178 thread_running_task.Start();
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 SkipOnShutdown, 417 SkipOnShutdown,
416 TaskSchedulerTaskTrackerTest, 418 TaskSchedulerTaskTrackerTest,
417 ::testing::Values(TaskShutdownBehavior::SKIP_ON_SHUTDOWN)); 419 ::testing::Values(TaskShutdownBehavior::SKIP_ON_SHUTDOWN));
418 INSTANTIATE_TEST_CASE_P( 420 INSTANTIATE_TEST_CASE_P(
419 BlockShutdown, 421 BlockShutdown,
420 TaskSchedulerTaskTrackerTest, 422 TaskSchedulerTaskTrackerTest,
421 ::testing::Values(TaskShutdownBehavior::BLOCK_SHUTDOWN)); 423 ::testing::Values(TaskShutdownBehavior::BLOCK_SHUTDOWN));
422 424
423 } // namespace internal 425 } // namespace internal
424 } // namespace base 426 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/task_scheduler_impl_unittest.cc ('k') | base/test/test_io_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698