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

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

Issue 2161213002: TaskScheduler: Bump thread priority during shutdown. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR robliao #5 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/scheduler_worker.cc ('k') | base/task_scheduler/task_tracker.h » ('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/scheduler_worker.h" 5 #include "base/task_scheduler/scheduler_worker.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/synchronization/condition_variable.h" 16 #include "base/synchronization/condition_variable.h"
17 #include "base/synchronization/waitable_event.h"
17 #include "base/task_scheduler/scheduler_lock.h" 18 #include "base/task_scheduler/scheduler_lock.h"
18 #include "base/task_scheduler/sequence.h" 19 #include "base/task_scheduler/sequence.h"
19 #include "base/task_scheduler/task.h" 20 #include "base/task_scheduler/task.h"
20 #include "base/task_scheduler/task_tracker.h" 21 #include "base/task_scheduler/task_tracker.h"
22 #include "base/threading/platform_thread.h"
21 #include "base/time/time.h" 23 #include "base/time/time.h"
22 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
23 25
24 namespace base { 26 namespace base {
25 namespace internal { 27 namespace internal {
26 namespace { 28 namespace {
27 29
28 const size_t kNumSequencesPerTest = 150; 30 const size_t kNumSequencesPerTest = 150;
29 31
30 // The test parameter is the number of Tasks per Sequence returned by GetWork(). 32 // The test parameter is the number of Tasks per Sequence returned by GetWork().
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 ThreadPriority::NORMAL, WrapUnique(delegate), &task_tracker, 416 ThreadPriority::NORMAL, WrapUnique(delegate), &task_tracker,
415 SchedulerWorker::InitialState::DETACHED); 417 SchedulerWorker::InitialState::DETACHED);
416 ASSERT_FALSE(worker->ThreadAliveForTesting()); 418 ASSERT_FALSE(worker->ThreadAliveForTesting());
417 worker->WakeUp(); 419 worker->WakeUp();
418 delegate->WaitForWorkToRun(); 420 delegate->WaitForWorkToRun();
419 delegate->WaitForDetachRequest(); 421 delegate->WaitForDetachRequest();
420 ASSERT_TRUE(worker->ThreadAliveForTesting()); 422 ASSERT_TRUE(worker->ThreadAliveForTesting());
421 worker->JoinForTesting(); 423 worker->JoinForTesting();
422 } 424 }
423 425
426 namespace {
427
428 class ExpectNormalPriorityDelegate : public SchedulerWorker::Delegate {
429 public:
430 ExpectNormalPriorityDelegate()
431 : get_work_event_(WaitableEvent::ResetPolicy::MANUAL,
432 WaitableEvent::InitialState::NOT_SIGNALED) {}
433
434 void WaitForGetWork() { get_work_event_.Wait(); }
435
436 // SchedulerWorker::Delegate:
437 void OnMainEntry(SchedulerWorker* worker) override {}
438 scoped_refptr<Sequence> GetWork(SchedulerWorker* worker) override {
439 EXPECT_EQ(ThreadPriority::NORMAL,
440 PlatformThread::GetCurrentThreadPriority());
441 get_work_event_.Signal();
442 return nullptr;
443 }
444 void ReEnqueueSequence(scoped_refptr<Sequence> sequence) override {}
445 TimeDelta GetSleepTimeout() override { return TimeDelta::Max(); }
446 bool CanDetach(SchedulerWorker* worker) override { return false; }
447
448 private:
449 WaitableEvent get_work_event_;
450
451 DISALLOW_COPY_AND_ASSIGN(ExpectNormalPriorityDelegate);
452 };
453
454 } // namespace
455
456 TEST(TaskSchedulerWorkerTest, BumpPriorityDuringShutdown) {
457 TaskTracker task_tracker;
458 task_tracker.SetHasShutdownStartedForTesting();
gab 2016/07/20 18:35:36 Just to make sure, if you comment out this line, t
fdoray 2016/07/20 20:30:37 As discussed offline, implemented ExpectPriorityDe
459
460 ExpectNormalPriorityDelegate* delegate = new ExpectNormalPriorityDelegate;
gab 2016/07/20 18:35:36 Bind to unique_ptr here and move it below (or Wrap
fdoray 2016/07/20 20:30:37 Done.
461 std::unique_ptr<SchedulerWorker> worker = SchedulerWorker::Create(
462 ThreadPriority::BACKGROUND, WrapUnique(delegate), &task_tracker,
463 SchedulerWorker::InitialState::ALIVE);
464 worker->WakeUp();
465 delegate->WaitForGetWork();
466 worker->JoinForTesting();
467 }
468
424 } // namespace 469 } // namespace
425 } // namespace internal 470 } // namespace internal
426 } // namespace base 471 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/scheduler_worker.cc ('k') | base/task_scheduler/task_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698