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

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

Issue 2873733003: Introduce SingleThreadTaskRunnerThreadMode (Closed)
Patch Set: Add missing "base" Created 3 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
« no previous file with comments | « base/task_scheduler/task_scheduler_impl.cc ('k') | base/test/scoped_task_scheduler.cc » ('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/task_scheduler_impl.h" 5 #include "base/task_scheduler/task_scheduler_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 {TaskPriority::USER_BLOCKING})); 377 {TaskPriority::USER_BLOCKING}));
378 EXPECT_EQ(12, scheduler_.GetMaxConcurrentTasksWithTraitsDeprecated( 378 EXPECT_EQ(12, scheduler_.GetMaxConcurrentTasksWithTraitsDeprecated(
379 {MayBlock(), TaskPriority::USER_BLOCKING})); 379 {MayBlock(), TaskPriority::USER_BLOCKING}));
380 } 380 }
381 381
382 // Verify that the RunsTasksOnCurrentThread() method of a SequencedTaskRunner 382 // Verify that the RunsTasksOnCurrentThread() method of a SequencedTaskRunner
383 // returns false when called from a task that isn't part of the sequence. 383 // returns false when called from a task that isn't part of the sequence.
384 TEST_F(TaskSchedulerImplTest, SequencedRunsTasksOnCurrentThread) { 384 TEST_F(TaskSchedulerImplTest, SequencedRunsTasksOnCurrentThread) {
385 StartTaskScheduler(); 385 StartTaskScheduler();
386 auto single_thread_task_runner = 386 auto single_thread_task_runner =
387 scheduler_.CreateSingleThreadTaskRunnerWithTraits(TaskTraits()); 387 scheduler_.CreateSingleThreadTaskRunnerWithTraits(
388 TaskTraits(), SingleThreadTaskRunnerThreadMode::SHARED);
388 auto sequenced_task_runner = 389 auto sequenced_task_runner =
389 scheduler_.CreateSequencedTaskRunnerWithTraits(TaskTraits()); 390 scheduler_.CreateSequencedTaskRunnerWithTraits(TaskTraits());
390 391
391 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, 392 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL,
392 WaitableEvent::InitialState::NOT_SIGNALED); 393 WaitableEvent::InitialState::NOT_SIGNALED);
393 single_thread_task_runner->PostTask( 394 single_thread_task_runner->PostTask(
394 FROM_HERE, 395 FROM_HERE,
395 BindOnce( 396 BindOnce(
396 [](scoped_refptr<TaskRunner> sequenced_task_runner, 397 [](scoped_refptr<TaskRunner> sequenced_task_runner,
397 WaitableEvent* task_ran) { 398 WaitableEvent* task_ran) {
398 EXPECT_FALSE(sequenced_task_runner->RunsTasksOnCurrentThread()); 399 EXPECT_FALSE(sequenced_task_runner->RunsTasksOnCurrentThread());
399 task_ran->Signal(); 400 task_ran->Signal();
400 }, 401 },
401 sequenced_task_runner, Unretained(&task_ran))); 402 sequenced_task_runner, Unretained(&task_ran)));
402 task_ran.Wait(); 403 task_ran.Wait();
403 } 404 }
404 405
405 // Verify that the RunsTasksOnCurrentThread() method of a SingleThreadTaskRunner 406 // Verify that the RunsTasksOnCurrentThread() method of a SingleThreadTaskRunner
406 // returns false when called from a task that isn't part of the sequence. 407 // returns false when called from a task that isn't part of the sequence.
407 TEST_F(TaskSchedulerImplTest, SingleThreadRunsTasksOnCurrentThread) { 408 TEST_F(TaskSchedulerImplTest, SingleThreadRunsTasksOnCurrentThread) {
408 StartTaskScheduler(); 409 StartTaskScheduler();
409 auto sequenced_task_runner = 410 auto sequenced_task_runner =
410 scheduler_.CreateSequencedTaskRunnerWithTraits(TaskTraits()); 411 scheduler_.CreateSequencedTaskRunnerWithTraits(TaskTraits());
411 auto single_thread_task_runner = 412 auto single_thread_task_runner =
412 scheduler_.CreateSingleThreadTaskRunnerWithTraits(TaskTraits()); 413 scheduler_.CreateSingleThreadTaskRunnerWithTraits(
414 TaskTraits(), SingleThreadTaskRunnerThreadMode::SHARED);
413 415
414 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, 416 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL,
415 WaitableEvent::InitialState::NOT_SIGNALED); 417 WaitableEvent::InitialState::NOT_SIGNALED);
416 sequenced_task_runner->PostTask( 418 sequenced_task_runner->PostTask(
417 FROM_HERE, 419 FROM_HERE,
418 BindOnce( 420 BindOnce(
419 [](scoped_refptr<TaskRunner> single_thread_task_runner, 421 [](scoped_refptr<TaskRunner> single_thread_task_runner,
420 WaitableEvent* task_ran) { 422 WaitableEvent* task_ran) {
421 EXPECT_FALSE(single_thread_task_runner->RunsTasksOnCurrentThread()); 423 EXPECT_FALSE(single_thread_task_runner->RunsTasksOnCurrentThread());
422 task_ran->Signal(); 424 task_ran->Signal();
423 }, 425 },
424 single_thread_task_runner, Unretained(&task_ran))); 426 single_thread_task_runner, Unretained(&task_ran)));
425 task_ran.Wait(); 427 task_ran.Wait();
426 } 428 }
427 429
428 #if defined(OS_WIN) 430 #if defined(OS_WIN)
429 TEST_F(TaskSchedulerImplTest, COMSTATaskRunnersRunWithCOMSTA) { 431 TEST_F(TaskSchedulerImplTest, COMSTATaskRunnersRunWithCOMSTA) {
430 StartTaskScheduler(); 432 StartTaskScheduler();
431 auto com_sta_task_runner = 433 auto com_sta_task_runner = scheduler_.CreateCOMSTATaskRunnerWithTraits(
432 scheduler_.CreateCOMSTATaskRunnerWithTraits(TaskTraits()); 434 TaskTraits(), SingleThreadTaskRunnerThreadMode::SHARED);
433 435
434 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, 436 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL,
435 WaitableEvent::InitialState::NOT_SIGNALED); 437 WaitableEvent::InitialState::NOT_SIGNALED);
436 com_sta_task_runner->PostTask( 438 com_sta_task_runner->PostTask(
437 FROM_HERE, 439 FROM_HERE,
438 Bind( 440 Bind(
439 [](scoped_refptr<TaskRunner> single_thread_task_runner, 441 [](scoped_refptr<TaskRunner> single_thread_task_runner,
440 WaitableEvent* task_ran) { 442 WaitableEvent* task_ran) {
441 HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED); 443 HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
442 if (SUCCEEDED(hr)) { 444 if (SUCCEEDED(hr)) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 // Give a chance for the file watcher to fire before closing the handles. 515 // Give a chance for the file watcher to fire before closing the handles.
514 PlatformThread::Sleep(TestTimeouts::tiny_timeout()); 516 PlatformThread::Sleep(TestTimeouts::tiny_timeout());
515 517
516 EXPECT_EQ(0, IGNORE_EINTR(close(pipes[0]))); 518 EXPECT_EQ(0, IGNORE_EINTR(close(pipes[0])));
517 EXPECT_EQ(0, IGNORE_EINTR(close(pipes[1]))); 519 EXPECT_EQ(0, IGNORE_EINTR(close(pipes[1])));
518 } 520 }
519 #endif // defined(OS_POSIX) 521 #endif // defined(OS_POSIX)
520 522
521 } // namespace internal 523 } // namespace internal
522 } // namespace base 524 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/task_scheduler_impl.cc ('k') | base/test/scoped_task_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698