| OLD | NEW |
| 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_tracker.h" | 5 #include "base/task_scheduler/task_tracker.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 TEST_P(TaskSchedulerTaskTrackerTest, FlushPendingDelayedTask) { | 491 TEST_P(TaskSchedulerTaskTrackerTest, FlushPendingDelayedTask) { |
| 492 const Task delayed_task(FROM_HERE, Bind(&DoNothing), | 492 const Task delayed_task(FROM_HERE, Bind(&DoNothing), |
| 493 TaskTraits().WithShutdownBehavior(GetParam()), | 493 TaskTraits().WithShutdownBehavior(GetParam()), |
| 494 TimeDelta::FromDays(1)); | 494 TimeDelta::FromDays(1)); |
| 495 tracker_.WillPostTask(&delayed_task); | 495 tracker_.WillPostTask(&delayed_task); |
| 496 // Flush() should return even if the delayed task didn't run. | 496 // Flush() should return even if the delayed task didn't run. |
| 497 tracker_.Flush(); | 497 tracker_.Flush(); |
| 498 } | 498 } |
| 499 | 499 |
| 500 TEST_P(TaskSchedulerTaskTrackerTest, FlushPendingUndelayedTask) { | 500 TEST_P(TaskSchedulerTaskTrackerTest, FlushPendingUndelayedTask) { |
| 501 const Task undelayed_task(FROM_HERE, Bind(&DoNothing), | 501 Task undelayed_task(FROM_HERE, Bind(&DoNothing), |
| 502 TaskTraits().WithShutdownBehavior(GetParam()), | 502 TaskTraits().WithShutdownBehavior(GetParam()), |
| 503 TimeDelta()); | 503 TimeDelta()); |
| 504 tracker_.WillPostTask(&undelayed_task); | 504 tracker_.WillPostTask(&undelayed_task); |
| 505 | 505 |
| 506 // Flush() shouldn't return before the undelayed task runs. | 506 // Flush() shouldn't return before the undelayed task runs. |
| 507 CallFlushAsync(); | 507 CallFlushAsync(); |
| 508 PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | 508 PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
| 509 VERIFY_ASYNC_FLUSH_IN_PROGRESS(); | 509 VERIFY_ASYNC_FLUSH_IN_PROGRESS(); |
| 510 | 510 |
| 511 // Flush() should return after the undelayed task runs. | 511 // Flush() should return after the undelayed task runs. |
| 512 tracker_.RunTask(&undelayed_task, SequenceToken::Create()); | 512 tracker_.RunTask(&undelayed_task, SequenceToken::Create()); |
| 513 WAIT_FOR_ASYNC_FLUSH_RETURNED(); | 513 WAIT_FOR_ASYNC_FLUSH_RETURNED(); |
| 514 } | 514 } |
| 515 | 515 |
| 516 TEST_P(TaskSchedulerTaskTrackerTest, PostTaskDuringFlush) { | 516 TEST_P(TaskSchedulerTaskTrackerTest, PostTaskDuringFlush) { |
| 517 const Task undelayed_task(FROM_HERE, Bind(&DoNothing), | 517 Task undelayed_task(FROM_HERE, Bind(&DoNothing), |
| 518 TaskTraits().WithShutdownBehavior(GetParam()), | 518 TaskTraits().WithShutdownBehavior(GetParam()), |
| 519 TimeDelta()); | 519 TimeDelta()); |
| 520 tracker_.WillPostTask(&undelayed_task); | 520 tracker_.WillPostTask(&undelayed_task); |
| 521 | 521 |
| 522 // Flush() shouldn't return before the undelayed task runs. | 522 // Flush() shouldn't return before the undelayed task runs. |
| 523 CallFlushAsync(); | 523 CallFlushAsync(); |
| 524 PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | 524 PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
| 525 VERIFY_ASYNC_FLUSH_IN_PROGRESS(); | 525 VERIFY_ASYNC_FLUSH_IN_PROGRESS(); |
| 526 | 526 |
| 527 // Simulate posting another undelayed task. | 527 // Simulate posting another undelayed task. |
| 528 const Task other_undelayed_task(FROM_HERE, Bind(&DoNothing), | 528 Task other_undelayed_task(FROM_HERE, Bind(&DoNothing), |
| 529 TaskTraits().WithShutdownBehavior(GetParam()), | 529 TaskTraits().WithShutdownBehavior(GetParam()), |
| 530 TimeDelta()); | 530 TimeDelta()); |
| 531 tracker_.WillPostTask(&other_undelayed_task); | 531 tracker_.WillPostTask(&other_undelayed_task); |
| 532 | 532 |
| 533 // Run the first undelayed task. | 533 // Run the first undelayed task. |
| 534 tracker_.RunTask(&undelayed_task, SequenceToken::Create()); | 534 tracker_.RunTask(&undelayed_task, SequenceToken::Create()); |
| 535 | 535 |
| 536 // Flush() shouldn't return before the second undelayed task runs. | 536 // Flush() shouldn't return before the second undelayed task runs. |
| 537 PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | 537 PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
| 538 VERIFY_ASYNC_FLUSH_IN_PROGRESS(); | 538 VERIFY_ASYNC_FLUSH_IN_PROGRESS(); |
| 539 | 539 |
| 540 // Flush() should return after the second undelayed task runs. | 540 // Flush() should return after the second undelayed task runs. |
| 541 tracker_.RunTask(&other_undelayed_task, SequenceToken::Create()); | 541 tracker_.RunTask(&other_undelayed_task, SequenceToken::Create()); |
| 542 WAIT_FOR_ASYNC_FLUSH_RETURNED(); | 542 WAIT_FOR_ASYNC_FLUSH_RETURNED(); |
| 543 } | 543 } |
| 544 | 544 |
| 545 TEST_P(TaskSchedulerTaskTrackerTest, RunDelayedTaskDuringFlush) { | 545 TEST_P(TaskSchedulerTaskTrackerTest, RunDelayedTaskDuringFlush) { |
| 546 // Simulate posting a delayed and an undelayed task. | 546 // Simulate posting a delayed and an undelayed task. |
| 547 const Task delayed_task(FROM_HERE, Bind(&DoNothing), | 547 Task delayed_task(FROM_HERE, Bind(&DoNothing), |
| 548 TaskTraits().WithShutdownBehavior(GetParam()), | 548 TaskTraits().WithShutdownBehavior(GetParam()), |
| 549 TimeDelta::FromDays(1)); | 549 TimeDelta::FromDays(1)); |
| 550 tracker_.WillPostTask(&delayed_task); | 550 tracker_.WillPostTask(&delayed_task); |
| 551 const Task undelayed_task(FROM_HERE, Bind(&DoNothing), | 551 Task undelayed_task(FROM_HERE, Bind(&DoNothing), |
| 552 TaskTraits().WithShutdownBehavior(GetParam()), | 552 TaskTraits().WithShutdownBehavior(GetParam()), |
| 553 TimeDelta()); | 553 TimeDelta()); |
| 554 tracker_.WillPostTask(&undelayed_task); | 554 tracker_.WillPostTask(&undelayed_task); |
| 555 | 555 |
| 556 // Flush() shouldn't return before the undelayed task runs. | 556 // Flush() shouldn't return before the undelayed task runs. |
| 557 CallFlushAsync(); | 557 CallFlushAsync(); |
| 558 PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | 558 PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
| 559 VERIFY_ASYNC_FLUSH_IN_PROGRESS(); | 559 VERIFY_ASYNC_FLUSH_IN_PROGRESS(); |
| 560 | 560 |
| 561 // Run the delayed task. | 561 // Run the delayed task. |
| 562 tracker_.RunTask(&delayed_task, SequenceToken::Create()); | 562 tracker_.RunTask(&delayed_task, SequenceToken::Create()); |
| 563 | 563 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 | 781 |
| 782 // Unblock shutdown by running |block_shutdown_task|. | 782 // Unblock shutdown by running |block_shutdown_task|. |
| 783 EXPECT_TRUE( | 783 EXPECT_TRUE( |
| 784 tracker_.RunTask(block_shutdown_task.get(), SequenceToken::Create())); | 784 tracker_.RunTask(block_shutdown_task.get(), SequenceToken::Create())); |
| 785 EXPECT_EQ(kLoadTestNumIterations + 1, NumTasksExecuted()); | 785 EXPECT_EQ(kLoadTestNumIterations + 1, NumTasksExecuted()); |
| 786 WAIT_FOR_ASYNC_SHUTDOWN_COMPLETED(); | 786 WAIT_FOR_ASYNC_SHUTDOWN_COMPLETED(); |
| 787 } | 787 } |
| 788 | 788 |
| 789 } // namespace internal | 789 } // namespace internal |
| 790 } // namespace base | 790 } // namespace base |
| OLD | NEW |