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

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: Review comments. 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 base::WaitableEvent completion(false, false);
128 129
129 EXPECT_CALL(*task, run()); 130 EXPECT_CALL(*task, run());
130 ON_CALL(*task, run()) 131 ON_CALL(*task, run())
131 .WillByDefault(Invoke([&completion]() { completion.Signal(); })); 132 .WillByDefault(Invoke([&completion]() { completion.Signal(); }));
132 133
133 thread_->postTask(blink::WebTraceLocation(), task.release()); 134 thread_->postTask(blink::WebTraceLocation(), task.release());
134 thread_.reset(); 135 thread_.reset();
136 completion.Wait();
137 }
138
139 TEST_F(WebThreadImplForWorkerSchedulerTest,
140 TestThreadShutdownAfterPreShutdown) {
141 scoped_ptr<MockTask> task(new MockTask());
142 base::WaitableEvent completion(false, false);
143
144 ON_CALL(*task, run())
145 .WillByDefault(Invoke([&completion]() { completion.Signal(); }));
146
147 // preShutdown should block the postTask, but not the internal shutdown task.
148 thread_->scheduler()->preShutdown();
149 thread_->postTask(blink::WebTraceLocation(), task.release());
150 thread_.reset();
151
152 EXPECT_FALSE(completion.IsSignaled());
135 } 153 }
136 154
137 TEST_F(WebThreadImplForWorkerSchedulerTest, TestIdleTask) { 155 TEST_F(WebThreadImplForWorkerSchedulerTest, TestIdleTask) {
138 scoped_ptr<MockIdleTask> task(new MockIdleTask()); 156 scoped_ptr<MockIdleTask> task(new MockIdleTask());
139 base::WaitableEvent completion(false, false); 157 base::WaitableEvent completion(false, false);
140 158
141 EXPECT_CALL(*task, run(_)); 159 EXPECT_CALL(*task, run(_));
142 ON_CALL(*task, run(_)) 160 ON_CALL(*task, run(_))
143 .WillByDefault(Invoke([&completion](double) { completion.Signal(); })); 161 .WillByDefault(Invoke([&completion](double) { completion.Signal(); }));
144 162
(...skipping 16 matching lines...) Expand all
161 179
162 // We need to be careful what we test here. We want to make sure the 180 // 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. 181 // observers are un in the expected order before and after the task.
164 // Sometimes we get an internal scheduler task running before or after 182 // 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 183 // TestTask as well. This is not a bug, and we need to make sure the test
166 // doesn't fail when that happens. 184 // doesn't fail when that happens.
167 EXPECT_THAT(calls, testing::HasSubstr("willProcessTask run didProcessTask")); 185 EXPECT_THAT(calls, testing::HasSubstr("willProcessTask run didProcessTask"));
168 } 186 }
169 187
170 } // namespace scheduler 188 } // namespace scheduler
OLDNEW
« no previous file with comments | « components/scheduler/child/webthread_impl_for_worker_scheduler.cc ('k') | components/scheduler/child/worker_scheduler_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698