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

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

Issue 2208493002: TaskScheduler: No BACKGROUND threads when unsupported. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + CR robliao #6 (nit) Created 4 years, 4 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 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>
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 SchedulerLock expected_thread_priority_lock_; 467 SchedulerLock expected_thread_priority_lock_;
468 468
469 // Expected thread priority for the next call to OnMainEntry() or GetWork(). 469 // Expected thread priority for the next call to OnMainEntry() or GetWork().
470 ThreadPriority expected_thread_priority_; 470 ThreadPriority expected_thread_priority_;
471 471
472 DISALLOW_COPY_AND_ASSIGN(ExpectThreadPriorityDelegate); 472 DISALLOW_COPY_AND_ASSIGN(ExpectThreadPriorityDelegate);
473 }; 473 };
474 474
475 } // namespace 475 } // namespace
476 476
477 // Increasing the thread priority requires the CAP_SYS_NICE capability on Linux.
478 #if !defined(OS_LINUX)
479 TEST(TaskSchedulerWorkerTest, BumpPriorityOfAliveThreadDuringShutdown) { 477 TEST(TaskSchedulerWorkerTest, BumpPriorityOfAliveThreadDuringShutdown) {
480 TaskTracker task_tracker; 478 TaskTracker task_tracker;
481 479
482 std::unique_ptr<ExpectThreadPriorityDelegate> delegate( 480 std::unique_ptr<ExpectThreadPriorityDelegate> delegate(
483 new ExpectThreadPriorityDelegate); 481 new ExpectThreadPriorityDelegate);
484 ExpectThreadPriorityDelegate* delegate_raw = delegate.get(); 482 ExpectThreadPriorityDelegate* delegate_raw = delegate.get();
485 delegate_raw->SetExpectedThreadPriority(ThreadPriority::BACKGROUND); 483 delegate_raw->SetExpectedThreadPriority(
484 PlatformThread::CanIncreaseCurrentThreadPriority()
485 ? ThreadPriority::BACKGROUND
486 : ThreadPriority::NORMAL);
486 487
487 std::unique_ptr<SchedulerWorker> worker = SchedulerWorker::Create( 488 std::unique_ptr<SchedulerWorker> worker = SchedulerWorker::Create(
488 ThreadPriority::BACKGROUND, std::move(delegate), &task_tracker, 489 ThreadPriority::BACKGROUND, std::move(delegate), &task_tracker,
489 SchedulerWorker::InitialState::ALIVE); 490 SchedulerWorker::InitialState::ALIVE);
490 491
491 // Verify that the initial thread priority is BACKGROUND. 492 // Verify that the initial thread priority is BACKGROUND (or NORMAL if thread
493 // priority can't be increased).
492 worker->WakeUp(); 494 worker->WakeUp();
493 delegate_raw->WaitForPriorityVerifiedInGetWork(); 495 delegate_raw->WaitForPriorityVerifiedInGetWork();
494 496
495 // Verify that the thread priority is bumped to NORMAL during shutdown. 497 // Verify that the thread priority is bumped to NORMAL during shutdown.
496 delegate_raw->SetExpectedThreadPriority(ThreadPriority::NORMAL); 498 delegate_raw->SetExpectedThreadPriority(ThreadPriority::NORMAL);
497 task_tracker.SetHasShutdownStartedForTesting(); 499 task_tracker.SetHasShutdownStartedForTesting();
498 worker->WakeUp(); 500 worker->WakeUp();
499 delegate_raw->WaitForPriorityVerifiedInGetWork(); 501 delegate_raw->WaitForPriorityVerifiedInGetWork();
500 502
501 worker->JoinForTesting(); 503 worker->JoinForTesting();
502 } 504 }
503 #endif // defined(OS_LINUX)
504 505
505 TEST(TaskSchedulerWorkerTest, BumpPriorityOfDetachedThreadDuringShutdown) { 506 TEST(TaskSchedulerWorkerTest, BumpPriorityOfDetachedThreadDuringShutdown) {
506 TaskTracker task_tracker; 507 TaskTracker task_tracker;
507 508
508 std::unique_ptr<ExpectThreadPriorityDelegate> delegate( 509 std::unique_ptr<ExpectThreadPriorityDelegate> delegate(
509 new ExpectThreadPriorityDelegate); 510 new ExpectThreadPriorityDelegate);
510 ExpectThreadPriorityDelegate* delegate_raw = delegate.get(); 511 ExpectThreadPriorityDelegate* delegate_raw = delegate.get();
511 delegate_raw->SetExpectedThreadPriority(ThreadPriority::NORMAL); 512 delegate_raw->SetExpectedThreadPriority(ThreadPriority::NORMAL);
512 513
513 // Create a DETACHED thread. 514 // Create a DETACHED thread.
514 std::unique_ptr<SchedulerWorker> worker = SchedulerWorker::Create( 515 std::unique_ptr<SchedulerWorker> worker = SchedulerWorker::Create(
515 ThreadPriority::BACKGROUND, std::move(delegate), &task_tracker, 516 ThreadPriority::BACKGROUND, std::move(delegate), &task_tracker,
516 SchedulerWorker::InitialState::DETACHED); 517 SchedulerWorker::InitialState::DETACHED);
517 518
518 // Pretend that shutdown has started. 519 // Pretend that shutdown has started.
519 task_tracker.SetHasShutdownStartedForTesting(); 520 task_tracker.SetHasShutdownStartedForTesting();
520 521
521 // Wake up the thread and verify that its priority is NORMAL when 522 // Wake up the thread and verify that its priority is NORMAL when
522 // OnMainEntry() and GetWork() are called. 523 // OnMainEntry() and GetWork() are called.
523 worker->WakeUp(); 524 worker->WakeUp();
524 delegate_raw->WaitForPriorityVerifiedInGetWork(); 525 delegate_raw->WaitForPriorityVerifiedInGetWork();
525 526
526 worker->JoinForTesting(); 527 worker->JoinForTesting();
527 } 528 }
528 529
529 } // namespace 530 } // namespace
530 } // namespace internal 531 } // namespace internal
531 } // namespace base 532 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/scheduler_worker_pool_params.cc ('k') | base/task_scheduler/task_scheduler_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698