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

Side by Side Diff: components/scheduler/child/webthread_impl_for_worker_scheduler_unittest.cc

Issue 1106213002: Adds a SHUTDOWN_TASK_QUEUE and a PreShutdown api to the scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/scheduler/child/webthread_impl_for_worker_scheduler.h" 5 #include "components/scheduler/child/webthread_impl_for_worker_scheduler.h"
6 6
7 #include "base/synchronization/waitable_event.h" 7 #include "base/synchronization/waitable_event.h"
8 #include "components/scheduler/child/worker_scheduler_impl.h" 8 #include "components/scheduler/child/worker_scheduler_impl.h"
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/WebKit/public/platform/WebScheduler.h"
11 #include "third_party/WebKit/public/platform/WebTraceLocation.h" 12 #include "third_party/WebKit/public/platform/WebTraceLocation.h"
12 13
13 using testing::_; 14 using testing::_;
14 using testing::AnyOf; 15 using testing::AnyOf;
15 using testing::ElementsAre; 16 using testing::ElementsAre;
16 using testing::Invoke; 17 using testing::Invoke;
17 18
18 namespace scheduler { 19 namespace scheduler {
19 namespace { 20 namespace {
20 21
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 ON_CALL(*task, run()) 118 ON_CALL(*task, run())
118 .WillByDefault(Invoke([&completion]() { completion.Signal(); })); 119 .WillByDefault(Invoke([&completion]() { completion.Signal(); }));
119 120
120 thread_->postTask(blink::WebTraceLocation(), task.release()); 121 thread_->postTask(blink::WebTraceLocation(), task.release());
121 completion.Wait(); 122 completion.Wait();
122 } 123 }
123 124
124 TEST_F(WebThreadImplForWorkerSchedulerTest, 125 TEST_F(WebThreadImplForWorkerSchedulerTest,
125 TestTaskExecutedBeforeThreadDeletion) { 126 TestTaskExecutedBeforeThreadDeletion) {
126 scoped_ptr<MockTask> task(new MockTask()); 127 scoped_ptr<MockTask> task(new MockTask());
127 base::WaitableEvent completion(false, false); 128 bool task_ran = false;
129 base::Lock lock;
rmcilroy 2015/04/28 09:51:10 Can you not just use a WaitableEvent and check !co
Sami 2015/04/28 11:52:46 Good idea, that's cleaner. Also found out that th
128 130
129 EXPECT_CALL(*task, run()); 131 EXPECT_CALL(*task, run());
130 ON_CALL(*task, run()) 132 ON_CALL(*task, run())
131 .WillByDefault(Invoke([&completion]() { completion.Signal(); })); 133 .WillByDefault(Invoke([&task_ran, &lock]() {
134 base::AutoLock auto_lock(lock);
135 task_ran = true;
136 }));
132 137
133 thread_->postTask(blink::WebTraceLocation(), task.release()); 138 thread_->postTask(blink::WebTraceLocation(), task.release());
134 thread_.reset(); 139 thread_.reset();
140 {
141 base::AutoLock auto_lock(lock);
142 EXPECT_TRUE(task_ran);
143 }
144 }
145
146 TEST_F(WebThreadImplForWorkerSchedulerTest,
147 TestThreadShutdownAfterPreShutdown) {
148 scoped_ptr<MockTask> task(new MockTask());
149 bool task_ran = false;
150 base::Lock lock;
151
152 ON_CALL(*task, run())
153 .WillByDefault(Invoke([&task_ran, &lock]() {
154 base::AutoLock auto_lock(lock);
155 task_ran = true;
156 }));
157
158 // preShutdown should block the postTask, but not the internal shutdown task.
159 thread_->scheduler()->preShutdown();
160 thread_->postTask(blink::WebTraceLocation(), task.release());
161 thread_.reset();
162
163 {
164 base::AutoLock auto_lock(lock);
165 EXPECT_FALSE(task_ran);
166 }
135 } 167 }
136 168
137 TEST_F(WebThreadImplForWorkerSchedulerTest, TestIdleTask) { 169 TEST_F(WebThreadImplForWorkerSchedulerTest, TestIdleTask) {
138 scoped_ptr<MockIdleTask> task(new MockIdleTask()); 170 scoped_ptr<MockIdleTask> task(new MockIdleTask());
139 base::WaitableEvent completion(false, false); 171 base::WaitableEvent completion(false, false);
140 172
141 EXPECT_CALL(*task, run(_)); 173 EXPECT_CALL(*task, run(_));
142 ON_CALL(*task, run(_)) 174 ON_CALL(*task, run(_))
143 .WillByDefault(Invoke([&completion](double) { completion.Signal(); })); 175 .WillByDefault(Invoke([&completion](double) { completion.Signal(); }));
144 176
(...skipping 16 matching lines...) Expand all
161 193
162 // We need to be careful what we test here. We want to make sure the 194 // We need to be careful what we test here. We want to make sure the
163 // observers are un in the expected order before and after the task. 195 // observers are un in the expected order before and after the task.
164 // Sometimes we get an internal scheduler task running before or after 196 // Sometimes we get an internal scheduler task running before or after
165 // TestTask as well. This is not a bug, and we need to make sure the test 197 // TestTask as well. This is not a bug, and we need to make sure the test
166 // doesn't fail when that happens. 198 // doesn't fail when that happens.
167 EXPECT_THAT(calls, testing::HasSubstr("willProcessTask run didProcessTask")); 199 EXPECT_THAT(calls, testing::HasSubstr("willProcessTask run didProcessTask"));
168 } 200 }
169 201
170 } // namespace scheduler 202 } // namespace scheduler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698