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

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

Issue 2161213002: TaskScheduler: Bump thread priority during shutdown. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR gab #26 (Set* -> Update* and disable on Linux) Created 4 years, 5 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_tracker.cc ('k') | no next file » | 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 TaskTraits().WithShutdownBehavior(shutdown_behavior), TimeDelta())); 125 TaskTraits().WithShutdownBehavior(shutdown_behavior), TimeDelta()));
126 } 126 }
127 127
128 // Calls tracker_->Shutdown() on a new thread. When this returns, Shutdown() 128 // Calls tracker_->Shutdown() on a new thread. When this returns, Shutdown()
129 // method has been entered on the new thread, but it hasn't necessarily 129 // method has been entered on the new thread, but it hasn't necessarily
130 // returned. 130 // returned.
131 void CallShutdownAsync() { 131 void CallShutdownAsync() {
132 ASSERT_FALSE(thread_calling_shutdown_); 132 ASSERT_FALSE(thread_calling_shutdown_);
133 thread_calling_shutdown_.reset(new ThreadCallingShutdown(&tracker_)); 133 thread_calling_shutdown_.reset(new ThreadCallingShutdown(&tracker_));
134 thread_calling_shutdown_->Start(); 134 thread_calling_shutdown_->Start();
135 while (!tracker_.IsShuttingDownForTesting() && 135 while (!tracker_.HasShutdownStarted())
136 !tracker_.IsShutdownComplete()) {
137 PlatformThread::YieldCurrentThread(); 136 PlatformThread::YieldCurrentThread();
138 }
139 } 137 }
140 138
141 void WaitForAsyncIsShutdownComplete() { 139 void WaitForAsyncIsShutdownComplete() {
142 ASSERT_TRUE(thread_calling_shutdown_); 140 ASSERT_TRUE(thread_calling_shutdown_);
143 thread_calling_shutdown_->Join(); 141 thread_calling_shutdown_->Join();
144 EXPECT_TRUE(thread_calling_shutdown_->has_returned()); 142 EXPECT_TRUE(thread_calling_shutdown_->has_returned());
145 EXPECT_TRUE(tracker_.IsShutdownComplete()); 143 EXPECT_TRUE(tracker_.IsShutdownComplete());
146 } 144 }
147 145
148 void VerifyAsyncShutdownInProgress() { 146 void VerifyAsyncShutdownInProgress() {
149 ASSERT_TRUE(thread_calling_shutdown_); 147 ASSERT_TRUE(thread_calling_shutdown_);
150 EXPECT_FALSE(thread_calling_shutdown_->has_returned()); 148 EXPECT_FALSE(thread_calling_shutdown_->has_returned());
149 EXPECT_TRUE(tracker_.HasShutdownStarted());
151 EXPECT_FALSE(tracker_.IsShutdownComplete()); 150 EXPECT_FALSE(tracker_.IsShutdownComplete());
152 EXPECT_TRUE(tracker_.IsShuttingDownForTesting());
153 } 151 }
154 152
155 size_t NumTasksExecuted() { 153 size_t NumTasksExecuted() {
156 AutoSchedulerLock auto_lock(lock_); 154 AutoSchedulerLock auto_lock(lock_);
157 return num_tasks_executed_; 155 return num_tasks_executed_;
158 } 156 }
159 157
160 TaskTracker tracker_; 158 TaskTracker tracker_;
161 159
162 private: 160 private:
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 VERIFY_ASYNC_SHUTDOWN_IN_PROGRESS(); 594 VERIFY_ASYNC_SHUTDOWN_IN_PROGRESS();
597 595
598 // Unblock shutdown by running |block_shutdown_task|. 596 // Unblock shutdown by running |block_shutdown_task|.
599 tracker_.RunTask(block_shutdown_task.get()); 597 tracker_.RunTask(block_shutdown_task.get());
600 EXPECT_EQ(kLoadTestNumIterations + 1, NumTasksExecuted()); 598 EXPECT_EQ(kLoadTestNumIterations + 1, NumTasksExecuted());
601 WAIT_FOR_ASYNC_SHUTDOWN_COMPLETED(); 599 WAIT_FOR_ASYNC_SHUTDOWN_COMPLETED();
602 } 600 }
603 601
604 } // namespace internal 602 } // namespace internal
605 } // namespace base 603 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/task_tracker.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698