| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/threading/sequenced_worker_pool.h" | 5 #include "base/threading/sequenced_worker_pool.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 // PrepareToStartAdditionalThreadIfNecessary in the .cc file for more | 314 // PrepareToStartAdditionalThreadIfNecessary in the .cc file for more |
| 315 // details. | 315 // details. |
| 316 // | 316 // |
| 317 // It will post tasks to the queue with id -1. It also assumes this is the | 317 // It will post tasks to the queue with id -1. It also assumes this is the |
| 318 // first thing called in a test since it will clear the complete_sequence_. | 318 // first thing called in a test since it will clear the complete_sequence_. |
| 319 void EnsureAllWorkersCreated() { | 319 void EnsureAllWorkersCreated() { |
| 320 // Create a bunch of threads, all waiting. This will cause that may | 320 // Create a bunch of threads, all waiting. This will cause that may |
| 321 // workers to be created. | 321 // workers to be created. |
| 322 ThreadBlocker blocker; | 322 ThreadBlocker blocker; |
| 323 for (size_t i = 0; i < kNumWorkerThreads; i++) { | 323 for (size_t i = 0; i < kNumWorkerThreads; i++) { |
| 324 pool()->PostWorkerTask(FROM_HERE, | 324 pool()->PostWorkerTask( |
| 325 base::Bind(&TestTracker::BlockTask, | 325 FROM_HERE, |
| 326 tracker(), -1, &blocker)); | 326 base::BindOnce(&TestTracker::BlockTask, tracker(), -1, &blocker)); |
| 327 } | 327 } |
| 328 tracker()->WaitUntilTasksBlocked(kNumWorkerThreads); | 328 tracker()->WaitUntilTasksBlocked(kNumWorkerThreads); |
| 329 | 329 |
| 330 // Now wake them up and wait until they're done. | 330 // Now wake them up and wait until they're done. |
| 331 blocker.Unblock(kNumWorkerThreads); | 331 blocker.Unblock(kNumWorkerThreads); |
| 332 tracker()->WaitUntilTasksComplete(kNumWorkerThreads); | 332 tracker()->WaitUntilTasksComplete(kNumWorkerThreads); |
| 333 | 333 |
| 334 // Clean up the task IDs we added. | 334 // Clean up the task IDs we added. |
| 335 tracker()->ClearCompleteSequence(); | 335 tracker()->ClearCompleteSequence(); |
| 336 } | 336 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 }; | 376 }; |
| 377 | 377 |
| 378 void ShouldNotRun(const scoped_refptr<DeletionHelper>& helper) { | 378 void ShouldNotRun(const scoped_refptr<DeletionHelper>& helper) { |
| 379 ADD_FAILURE() << "Should never run"; | 379 ADD_FAILURE() << "Should never run"; |
| 380 } | 380 } |
| 381 | 381 |
| 382 // Tests that shutdown does not wait for delayed tasks. | 382 // Tests that shutdown does not wait for delayed tasks. |
| 383 TEST_P(SequencedWorkerPoolTest, DelayedTaskDuringShutdown) { | 383 TEST_P(SequencedWorkerPoolTest, DelayedTaskDuringShutdown) { |
| 384 // Post something to verify the pool is started up. | 384 // Post something to verify the pool is started up. |
| 385 EXPECT_TRUE(pool()->PostTask( | 385 EXPECT_TRUE(pool()->PostTask( |
| 386 FROM_HERE, base::Bind(&TestTracker::FastTask, tracker(), 1))); | 386 FROM_HERE, base::BindOnce(&TestTracker::FastTask, tracker(), 1))); |
| 387 | 387 |
| 388 scoped_refptr<base::RefCountedData<bool> > deleted_flag( | 388 scoped_refptr<base::RefCountedData<bool> > deleted_flag( |
| 389 new base::RefCountedData<bool>(false)); | 389 new base::RefCountedData<bool>(false)); |
| 390 | 390 |
| 391 base::Time posted_at(base::Time::Now()); | 391 base::Time posted_at(base::Time::Now()); |
| 392 // Post something that shouldn't run. | 392 // Post something that shouldn't run. |
| 393 EXPECT_TRUE(pool()->PostDelayedTask( | 393 EXPECT_TRUE(pool()->PostDelayedTask( |
| 394 FROM_HERE, | 394 FROM_HERE, |
| 395 base::Bind(&ShouldNotRun, | 395 base::BindOnce(&ShouldNotRun, |
| 396 make_scoped_refptr(new DeletionHelper(deleted_flag))), | 396 make_scoped_refptr(new DeletionHelper(deleted_flag))), |
| 397 TestTimeouts::action_timeout())); | 397 TestTimeouts::action_timeout())); |
| 398 | 398 |
| 399 std::vector<int> completion_sequence = tracker()->WaitUntilTasksComplete(1); | 399 std::vector<int> completion_sequence = tracker()->WaitUntilTasksComplete(1); |
| 400 ASSERT_EQ(1u, completion_sequence.size()); | 400 ASSERT_EQ(1u, completion_sequence.size()); |
| 401 ASSERT_EQ(1, completion_sequence[0]); | 401 ASSERT_EQ(1, completion_sequence[0]); |
| 402 | 402 |
| 403 // Shutdown the pool. | 403 // Shutdown the pool. |
| 404 pool()->Shutdown(); | 404 pool()->Shutdown(); |
| 405 if (RedirectedToTaskScheduler()) | 405 if (RedirectedToTaskScheduler()) |
| 406 TaskScheduler::GetInstance()->Shutdown(); | 406 TaskScheduler::GetInstance()->Shutdown(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 | 446 |
| 447 SequencedWorkerPool::SequenceToken token3again = | 447 SequencedWorkerPool::SequenceToken token3again = |
| 448 pool()->GetNamedSequenceToken(name3); | 448 pool()->GetNamedSequenceToken(name3); |
| 449 EXPECT_TRUE(token3.Equals(token3again)); | 449 EXPECT_TRUE(token3.Equals(token3again)); |
| 450 } | 450 } |
| 451 | 451 |
| 452 // Tests that posting a bunch of tasks (many more than the number of worker | 452 // Tests that posting a bunch of tasks (many more than the number of worker |
| 453 // threads) runs them all. | 453 // threads) runs them all. |
| 454 TEST_P(SequencedWorkerPoolTest, LotsOfTasks) { | 454 TEST_P(SequencedWorkerPoolTest, LotsOfTasks) { |
| 455 pool()->PostWorkerTask(FROM_HERE, | 455 pool()->PostWorkerTask(FROM_HERE, |
| 456 base::Bind(&TestTracker::SlowTask, tracker(), 0)); | 456 base::BindOnce(&TestTracker::SlowTask, tracker(), 0)); |
| 457 | 457 |
| 458 const size_t kNumTasks = 20; | 458 const size_t kNumTasks = 20; |
| 459 for (size_t i = 1; i < kNumTasks; i++) { | 459 for (size_t i = 1; i < kNumTasks; i++) { |
| 460 pool()->PostWorkerTask(FROM_HERE, | 460 pool()->PostWorkerTask( |
| 461 base::Bind(&TestTracker::FastTask, tracker(), i)); | 461 FROM_HERE, base::BindOnce(&TestTracker::FastTask, tracker(), i)); |
| 462 } | 462 } |
| 463 | 463 |
| 464 std::vector<int> result = tracker()->WaitUntilTasksComplete(kNumTasks); | 464 std::vector<int> result = tracker()->WaitUntilTasksComplete(kNumTasks); |
| 465 EXPECT_EQ(kNumTasks, result.size()); | 465 EXPECT_EQ(kNumTasks, result.size()); |
| 466 } | 466 } |
| 467 | 467 |
| 468 // Tests that posting a bunch of tasks (many more than the number of | 468 // Tests that posting a bunch of tasks (many more than the number of |
| 469 // worker threads) to two pools simultaneously runs them all twice. | 469 // worker threads) to two pools simultaneously runs them all twice. |
| 470 // This test is meant to shake out any concurrency issues between | 470 // This test is meant to shake out any concurrency issues between |
| 471 // pools (like histograms). | 471 // pools (like histograms). |
| (...skipping 19 matching lines...) Expand all Loading... |
| 491 } | 491 } |
| 492 | 492 |
| 493 // Test that tasks with the same sequence token are executed in order but don't | 493 // Test that tasks with the same sequence token are executed in order but don't |
| 494 // affect other tasks. | 494 // affect other tasks. |
| 495 TEST_P(SequencedWorkerPoolTest, Sequence) { | 495 TEST_P(SequencedWorkerPoolTest, Sequence) { |
| 496 // Fill all the worker threads except one. | 496 // Fill all the worker threads except one. |
| 497 const size_t kNumBackgroundTasks = kNumWorkerThreads - 1; | 497 const size_t kNumBackgroundTasks = kNumWorkerThreads - 1; |
| 498 ThreadBlocker background_blocker; | 498 ThreadBlocker background_blocker; |
| 499 for (size_t i = 0; i < kNumBackgroundTasks; i++) { | 499 for (size_t i = 0; i < kNumBackgroundTasks; i++) { |
| 500 pool()->PostWorkerTask(FROM_HERE, | 500 pool()->PostWorkerTask(FROM_HERE, |
| 501 base::Bind(&TestTracker::BlockTask, | 501 base::BindOnce(&TestTracker::BlockTask, tracker(), i, |
| 502 tracker(), i, &background_blocker)); | 502 &background_blocker)); |
| 503 } | 503 } |
| 504 tracker()->WaitUntilTasksBlocked(kNumBackgroundTasks); | 504 tracker()->WaitUntilTasksBlocked(kNumBackgroundTasks); |
| 505 | 505 |
| 506 // Create two tasks with the same sequence token, one that will block on the | 506 // Create two tasks with the same sequence token, one that will block on the |
| 507 // event, and one which will just complete quickly when it's run. Since there | 507 // event, and one which will just complete quickly when it's run. Since there |
| 508 // is one worker thread free, the first task will start and then block, and | 508 // is one worker thread free, the first task will start and then block, and |
| 509 // the second task should be waiting. | 509 // the second task should be waiting. |
| 510 ThreadBlocker blocker; | 510 ThreadBlocker blocker; |
| 511 SequencedWorkerPool::SequenceToken token1 = pool()->GetSequenceToken(); | 511 SequencedWorkerPool::SequenceToken token1 = pool()->GetSequenceToken(); |
| 512 pool()->PostSequencedWorkerTask( | 512 pool()->PostSequencedWorkerTask( |
| 513 token1, FROM_HERE, | 513 token1, FROM_HERE, |
| 514 base::Bind(&TestTracker::BlockTask, tracker(), 100, &blocker)); | 514 base::BindOnce(&TestTracker::BlockTask, tracker(), 100, &blocker)); |
| 515 pool()->PostSequencedWorkerTask( | 515 pool()->PostSequencedWorkerTask( |
| 516 token1, FROM_HERE, | 516 token1, FROM_HERE, |
| 517 base::Bind(&TestTracker::FastTask, tracker(), 101)); | 517 base::BindOnce(&TestTracker::FastTask, tracker(), 101)); |
| 518 EXPECT_EQ(0u, tracker()->WaitUntilTasksComplete(0).size()); | 518 EXPECT_EQ(0u, tracker()->WaitUntilTasksComplete(0).size()); |
| 519 | 519 |
| 520 // Create another two tasks as above with a different token. These will be | 520 // Create another two tasks as above with a different token. These will be |
| 521 // blocked since there are no slots to run. | 521 // blocked since there are no slots to run. |
| 522 SequencedWorkerPool::SequenceToken token2 = pool()->GetSequenceToken(); | 522 SequencedWorkerPool::SequenceToken token2 = pool()->GetSequenceToken(); |
| 523 pool()->PostSequencedWorkerTask( | 523 pool()->PostSequencedWorkerTask( |
| 524 token2, FROM_HERE, | 524 token2, FROM_HERE, |
| 525 base::Bind(&TestTracker::FastTask, tracker(), 200)); | 525 base::BindOnce(&TestTracker::FastTask, tracker(), 200)); |
| 526 pool()->PostSequencedWorkerTask( | 526 pool()->PostSequencedWorkerTask( |
| 527 token2, FROM_HERE, | 527 token2, FROM_HERE, |
| 528 base::Bind(&TestTracker::FastTask, tracker(), 201)); | 528 base::BindOnce(&TestTracker::FastTask, tracker(), 201)); |
| 529 EXPECT_EQ(0u, tracker()->WaitUntilTasksComplete(0).size()); | 529 EXPECT_EQ(0u, tracker()->WaitUntilTasksComplete(0).size()); |
| 530 | 530 |
| 531 // Let one background task complete. This should then let both tasks of | 531 // Let one background task complete. This should then let both tasks of |
| 532 // token2 run to completion in order. The second task of token1 should still | 532 // token2 run to completion in order. The second task of token1 should still |
| 533 // be blocked. | 533 // be blocked. |
| 534 background_blocker.Unblock(1); | 534 background_blocker.Unblock(1); |
| 535 std::vector<int> result = tracker()->WaitUntilTasksComplete(3); | 535 std::vector<int> result = tracker()->WaitUntilTasksComplete(3); |
| 536 ASSERT_EQ(3u, result.size()); | 536 ASSERT_EQ(3u, result.size()); |
| 537 EXPECT_EQ(200, result[1]); | 537 EXPECT_EQ(200, result[1]); |
| 538 EXPECT_EQ(201, result[2]); | 538 EXPECT_EQ(201, result[2]); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 551 EXPECT_EQ(101, result[result.size() - 1]); | 551 EXPECT_EQ(101, result[result.size() - 1]); |
| 552 } | 552 } |
| 553 | 553 |
| 554 // Tests that any tasks posted after Shutdown are ignored. | 554 // Tests that any tasks posted after Shutdown are ignored. |
| 555 // Disabled for flakiness. See http://crbug.com/166451. | 555 // Disabled for flakiness. See http://crbug.com/166451. |
| 556 TEST_P(SequencedWorkerPoolTest, DISABLED_IgnoresAfterShutdown) { | 556 TEST_P(SequencedWorkerPoolTest, DISABLED_IgnoresAfterShutdown) { |
| 557 // Start tasks to take all the threads and block them. | 557 // Start tasks to take all the threads and block them. |
| 558 EnsureAllWorkersCreated(); | 558 EnsureAllWorkersCreated(); |
| 559 ThreadBlocker blocker; | 559 ThreadBlocker blocker; |
| 560 for (size_t i = 0; i < kNumWorkerThreads; i++) { | 560 for (size_t i = 0; i < kNumWorkerThreads; i++) { |
| 561 pool()->PostWorkerTask(FROM_HERE, | 561 pool()->PostWorkerTask(FROM_HERE, base::BindOnce(&TestTracker::BlockTask, |
| 562 base::Bind(&TestTracker::BlockTask, | 562 tracker(), i, &blocker)); |
| 563 tracker(), i, &blocker)); | |
| 564 } | 563 } |
| 565 tracker()->WaitUntilTasksBlocked(kNumWorkerThreads); | 564 tracker()->WaitUntilTasksBlocked(kNumWorkerThreads); |
| 566 | 565 |
| 567 SetWillWaitForShutdownCallback( | 566 SetWillWaitForShutdownCallback( |
| 568 base::Bind(&EnsureTasksToCompleteCountAndUnblock, | 567 base::Bind(&EnsureTasksToCompleteCountAndUnblock, |
| 569 scoped_refptr<TestTracker>(tracker()), 0, | 568 scoped_refptr<TestTracker>(tracker()), 0, |
| 570 &blocker, kNumWorkerThreads)); | 569 &blocker, kNumWorkerThreads)); |
| 571 | 570 |
| 572 // Shutdown the worker pool. This should discard all non-blocking tasks. | 571 // Shutdown the worker pool. This should discard all non-blocking tasks. |
| 573 const int kMaxNewBlockingTasksAfterShutdown = 100; | 572 const int kMaxNewBlockingTasksAfterShutdown = 100; |
| 574 pool()->Shutdown(kMaxNewBlockingTasksAfterShutdown); | 573 pool()->Shutdown(kMaxNewBlockingTasksAfterShutdown); |
| 575 | 574 |
| 576 int old_has_work_call_count = has_work_call_count(); | 575 int old_has_work_call_count = has_work_call_count(); |
| 577 | 576 |
| 578 std::vector<int> result = | 577 std::vector<int> result = |
| 579 tracker()->WaitUntilTasksComplete(kNumWorkerThreads); | 578 tracker()->WaitUntilTasksComplete(kNumWorkerThreads); |
| 580 | 579 |
| 581 // The kNumWorkerThread items should have completed, in no particular order. | 580 // The kNumWorkerThread items should have completed, in no particular order. |
| 582 ASSERT_EQ(kNumWorkerThreads, result.size()); | 581 ASSERT_EQ(kNumWorkerThreads, result.size()); |
| 583 for (size_t i = 0; i < kNumWorkerThreads; i++) | 582 for (size_t i = 0; i < kNumWorkerThreads; i++) |
| 584 EXPECT_TRUE(ContainsValue(result, static_cast<int>(i))); | 583 EXPECT_TRUE(ContainsValue(result, static_cast<int>(i))); |
| 585 | 584 |
| 586 // No further tasks, regardless of shutdown mode, should be allowed. | 585 // No further tasks, regardless of shutdown mode, should be allowed. |
| 587 EXPECT_FALSE(pool()->PostWorkerTaskWithShutdownBehavior( | 586 EXPECT_FALSE(pool()->PostWorkerTaskWithShutdownBehavior( |
| 588 FROM_HERE, | 587 FROM_HERE, base::BindOnce(&TestTracker::FastTask, tracker(), 100), |
| 589 base::Bind(&TestTracker::FastTask, tracker(), 100), | |
| 590 SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)); | 588 SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)); |
| 591 EXPECT_FALSE(pool()->PostWorkerTaskWithShutdownBehavior( | 589 EXPECT_FALSE(pool()->PostWorkerTaskWithShutdownBehavior( |
| 592 FROM_HERE, | 590 FROM_HERE, base::BindOnce(&TestTracker::FastTask, tracker(), 101), |
| 593 base::Bind(&TestTracker::FastTask, tracker(), 101), | |
| 594 SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | 591 SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 595 EXPECT_FALSE(pool()->PostWorkerTaskWithShutdownBehavior( | 592 EXPECT_FALSE(pool()->PostWorkerTaskWithShutdownBehavior( |
| 596 FROM_HERE, | 593 FROM_HERE, base::BindOnce(&TestTracker::FastTask, tracker(), 102), |
| 597 base::Bind(&TestTracker::FastTask, tracker(), 102), | |
| 598 SequencedWorkerPool::BLOCK_SHUTDOWN)); | 594 SequencedWorkerPool::BLOCK_SHUTDOWN)); |
| 599 | 595 |
| 600 ASSERT_EQ(old_has_work_call_count, has_work_call_count()); | 596 ASSERT_EQ(old_has_work_call_count, has_work_call_count()); |
| 601 } | 597 } |
| 602 | 598 |
| 603 TEST_P(SequencedWorkerPoolTest, AllowsAfterShutdown) { | 599 TEST_P(SequencedWorkerPoolTest, AllowsAfterShutdown) { |
| 604 // Test that <n> new blocking tasks are allowed provided they're posted | 600 // Test that <n> new blocking tasks are allowed provided they're posted |
| 605 // by a running tasks. | 601 // by a running tasks. |
| 606 EnsureAllWorkersCreated(); | 602 EnsureAllWorkersCreated(); |
| 607 ThreadBlocker blocker; | 603 ThreadBlocker blocker; |
| 608 | 604 |
| 609 // Start tasks to take all the threads and block them. | 605 // Start tasks to take all the threads and block them. |
| 610 const int kNumBlockTasks = static_cast<int>(kNumWorkerThreads); | 606 const int kNumBlockTasks = static_cast<int>(kNumWorkerThreads); |
| 611 for (int i = 0; i < kNumBlockTasks; ++i) { | 607 for (int i = 0; i < kNumBlockTasks; ++i) { |
| 612 EXPECT_TRUE(pool()->PostWorkerTask( | 608 EXPECT_TRUE(pool()->PostWorkerTask( |
| 613 FROM_HERE, | 609 FROM_HERE, |
| 614 base::Bind(&TestTracker::BlockTask, tracker(), i, &blocker))); | 610 base::BindOnce(&TestTracker::BlockTask, tracker(), i, &blocker))); |
| 615 } | 611 } |
| 616 tracker()->WaitUntilTasksBlocked(kNumWorkerThreads); | 612 tracker()->WaitUntilTasksBlocked(kNumWorkerThreads); |
| 617 | 613 |
| 618 // Queue up shutdown blocking tasks behind those which will attempt to post | 614 // Queue up shutdown blocking tasks behind those which will attempt to post |
| 619 // additional tasks when run, PostAdditionalTasks attempts to post 3 | 615 // additional tasks when run, PostAdditionalTasks attempts to post 3 |
| 620 // new FastTasks, one for each shutdown_behavior. | 616 // new FastTasks, one for each shutdown_behavior. |
| 621 const int kNumQueuedTasks = static_cast<int>(kNumWorkerThreads); | 617 const int kNumQueuedTasks = static_cast<int>(kNumWorkerThreads); |
| 622 for (int i = 0; i < kNumQueuedTasks; ++i) { | 618 for (int i = 0; i < kNumQueuedTasks; ++i) { |
| 623 EXPECT_TRUE(pool()->PostWorkerTaskWithShutdownBehavior( | 619 EXPECT_TRUE(pool()->PostWorkerTaskWithShutdownBehavior( |
| 624 FROM_HERE, base::Bind(&TestTracker::PostAdditionalTasks, tracker(), i, | 620 FROM_HERE, |
| 625 base::RetainedRef(pool()), false), | 621 base::BindOnce(&TestTracker::PostAdditionalTasks, tracker(), i, |
| 622 base::RetainedRef(pool()), false), |
| 626 SequencedWorkerPool::BLOCK_SHUTDOWN)); | 623 SequencedWorkerPool::BLOCK_SHUTDOWN)); |
| 627 } | 624 } |
| 628 | 625 |
| 629 // Half the additional blocking tasks will be allowed to run. | 626 // Half the additional blocking tasks will be allowed to run. |
| 630 constexpr int kNumNewBlockingTasksToAllow = kNumWorkerThreads / 2; | 627 constexpr int kNumNewBlockingTasksToAllow = kNumWorkerThreads / 2; |
| 631 | 628 |
| 632 if (RedirectedToTaskScheduler()) { | 629 if (RedirectedToTaskScheduler()) { |
| 633 // When redirection to TaskScheduler is enabled, | 630 // When redirection to TaskScheduler is enabled, |
| 634 // SequencedWorkerPool::Shutdown() sets the number of additional | 631 // SequencedWorkerPool::Shutdown() sets the number of additional |
| 635 // BLOCK_SHUTDOWN tasks that can be posted and returns without waiting for | 632 // BLOCK_SHUTDOWN tasks that can be posted and returns without waiting for |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 TEST_P(SequencedWorkerPoolTest, | 664 TEST_P(SequencedWorkerPoolTest, |
| 668 AllowsBlockingTasksDuringShutdownOutsideOfRunningTask) { | 665 AllowsBlockingTasksDuringShutdownOutsideOfRunningTask) { |
| 669 EnsureAllWorkersCreated(); | 666 EnsureAllWorkersCreated(); |
| 670 ThreadBlocker blocker; | 667 ThreadBlocker blocker; |
| 671 | 668 |
| 672 // Start tasks to take all the threads and block them. | 669 // Start tasks to take all the threads and block them. |
| 673 const int kNumBlockTasks = static_cast<int>(kNumWorkerThreads); | 670 const int kNumBlockTasks = static_cast<int>(kNumWorkerThreads); |
| 674 for (int i = 0; i < kNumBlockTasks; ++i) { | 671 for (int i = 0; i < kNumBlockTasks; ++i) { |
| 675 EXPECT_TRUE(pool()->PostWorkerTask( | 672 EXPECT_TRUE(pool()->PostWorkerTask( |
| 676 FROM_HERE, | 673 FROM_HERE, |
| 677 base::Bind(&TestTracker::BlockTask, tracker(), i, &blocker))); | 674 base::BindOnce(&TestTracker::BlockTask, tracker(), i, &blocker))); |
| 678 } | 675 } |
| 679 tracker()->WaitUntilTasksBlocked(kNumWorkerThreads); | 676 tracker()->WaitUntilTasksBlocked(kNumWorkerThreads); |
| 680 | 677 |
| 681 constexpr int kNumNewBlockingTasksToAllow = 1; | 678 constexpr int kNumNewBlockingTasksToAllow = 1; |
| 682 | 679 |
| 683 if (RedirectedToTaskScheduler()) { | 680 if (RedirectedToTaskScheduler()) { |
| 684 // When redirection to TaskScheduler is enabled, | 681 // When redirection to TaskScheduler is enabled, |
| 685 // SequencedWorkerPool::Shutdown() sets the number of additional | 682 // SequencedWorkerPool::Shutdown() sets the number of additional |
| 686 // BLOCK_SHUTDOWN tasks that can be posted and returns without waiting for | 683 // BLOCK_SHUTDOWN tasks that can be posted and returns without waiting for |
| 687 // pending BLOCK_SHUTDOWN tasks to complete their execution. | 684 // pending BLOCK_SHUTDOWN tasks to complete their execution. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 // CONTINUE_ON_SHUTDOWN tasks and runs BLOCK_SHUTDOWN tasks. However, since it | 718 // CONTINUE_ON_SHUTDOWN tasks and runs BLOCK_SHUTDOWN tasks. However, since it |
| 722 // doesn't provide a way to run a callback from inside its Shutdown() method, | 719 // doesn't provide a way to run a callback from inside its Shutdown() method, |
| 723 // it would be hard to make this test work with redirection enabled. | 720 // it would be hard to make this test work with redirection enabled. |
| 724 if (RedirectedToTaskScheduler()) | 721 if (RedirectedToTaskScheduler()) |
| 725 return; | 722 return; |
| 726 | 723 |
| 727 // Start tasks to take all the threads and block them. | 724 // Start tasks to take all the threads and block them. |
| 728 EnsureAllWorkersCreated(); | 725 EnsureAllWorkersCreated(); |
| 729 ThreadBlocker blocker; | 726 ThreadBlocker blocker; |
| 730 for (size_t i = 0; i < kNumWorkerThreads; i++) { | 727 for (size_t i = 0; i < kNumWorkerThreads; i++) { |
| 731 pool()->PostWorkerTask(FROM_HERE, | 728 pool()->PostWorkerTask(FROM_HERE, base::BindOnce(&TestTracker::BlockTask, |
| 732 base::Bind(&TestTracker::BlockTask, | 729 tracker(), i, &blocker)); |
| 733 tracker(), i, &blocker)); | |
| 734 } | 730 } |
| 735 tracker()->WaitUntilTasksBlocked(kNumWorkerThreads); | 731 tracker()->WaitUntilTasksBlocked(kNumWorkerThreads); |
| 736 | 732 |
| 737 // Create some tasks with different shutdown modes. | 733 // Create some tasks with different shutdown modes. |
| 738 pool()->PostWorkerTaskWithShutdownBehavior( | 734 pool()->PostWorkerTaskWithShutdownBehavior( |
| 739 FROM_HERE, | 735 FROM_HERE, base::BindOnce(&TestTracker::FastTask, tracker(), 100), |
| 740 base::Bind(&TestTracker::FastTask, tracker(), 100), | |
| 741 SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 736 SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
| 742 pool()->PostWorkerTaskWithShutdownBehavior( | 737 pool()->PostWorkerTaskWithShutdownBehavior( |
| 743 FROM_HERE, | 738 FROM_HERE, base::BindOnce(&TestTracker::FastTask, tracker(), 101), |
| 744 base::Bind(&TestTracker::FastTask, tracker(), 101), | |
| 745 SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 739 SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 746 pool()->PostWorkerTaskWithShutdownBehavior( | 740 pool()->PostWorkerTaskWithShutdownBehavior( |
| 747 FROM_HERE, | 741 FROM_HERE, base::BindOnce(&TestTracker::FastTask, tracker(), 102), |
| 748 base::Bind(&TestTracker::FastTask, tracker(), 102), | |
| 749 SequencedWorkerPool::BLOCK_SHUTDOWN); | 742 SequencedWorkerPool::BLOCK_SHUTDOWN); |
| 750 | 743 |
| 751 // Shutdown the worker pool. This should discard all non-blocking tasks. | 744 // Shutdown the worker pool. This should discard all non-blocking tasks. |
| 752 SetWillWaitForShutdownCallback( | 745 SetWillWaitForShutdownCallback( |
| 753 base::Bind(&EnsureTasksToCompleteCountAndUnblock, | 746 base::Bind(&EnsureTasksToCompleteCountAndUnblock, |
| 754 scoped_refptr<TestTracker>(tracker()), 0, | 747 scoped_refptr<TestTracker>(tracker()), 0, |
| 755 &blocker, kNumWorkerThreads)); | 748 &blocker, kNumWorkerThreads)); |
| 756 pool()->Shutdown(); | 749 pool()->Shutdown(); |
| 757 | 750 |
| 758 std::vector<int> result = | 751 std::vector<int> result = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 771 scoped_refptr<TaskRunner> runner(pool()->GetTaskRunnerWithShutdownBehavior( | 764 scoped_refptr<TaskRunner> runner(pool()->GetTaskRunnerWithShutdownBehavior( |
| 772 SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)); | 765 SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)); |
| 773 scoped_refptr<SequencedTaskRunner> sequenced_runner( | 766 scoped_refptr<SequencedTaskRunner> sequenced_runner( |
| 774 pool()->GetSequencedTaskRunnerWithShutdownBehavior( | 767 pool()->GetSequencedTaskRunnerWithShutdownBehavior( |
| 775 pool()->GetSequenceToken(), | 768 pool()->GetSequenceToken(), |
| 776 SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)); | 769 SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)); |
| 777 EnsureAllWorkersCreated(); | 770 EnsureAllWorkersCreated(); |
| 778 ThreadBlocker blocker; | 771 ThreadBlocker blocker; |
| 779 pool()->PostWorkerTaskWithShutdownBehavior( | 772 pool()->PostWorkerTaskWithShutdownBehavior( |
| 780 FROM_HERE, | 773 FROM_HERE, |
| 781 base::Bind(&TestTracker::BlockTask, | 774 base::BindOnce(&TestTracker::BlockTask, tracker(), 0, &blocker), |
| 782 tracker(), 0, &blocker), | |
| 783 SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 775 SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
| 784 runner->PostTask( | 776 runner->PostTask(FROM_HERE, base::BindOnce(&TestTracker::BlockTask, tracker(), |
| 785 FROM_HERE, | 777 1, &blocker)); |
| 786 base::Bind(&TestTracker::BlockTask, | 778 sequenced_runner->PostTask(FROM_HERE, base::BindOnce(&TestTracker::BlockTask, |
| 787 tracker(), 1, &blocker)); | 779 tracker(), 2, &blocker)); |
| 788 sequenced_runner->PostTask( | |
| 789 FROM_HERE, | |
| 790 base::Bind(&TestTracker::BlockTask, | |
| 791 tracker(), 2, &blocker)); | |
| 792 | 780 |
| 793 tracker()->WaitUntilTasksBlocked(3); | 781 tracker()->WaitUntilTasksBlocked(3); |
| 794 | 782 |
| 795 // This should not block. If this test hangs, it means it failed. | 783 // This should not block. If this test hangs, it means it failed. |
| 796 pool()->Shutdown(); | 784 pool()->Shutdown(); |
| 797 if (RedirectedToTaskScheduler()) | 785 if (RedirectedToTaskScheduler()) |
| 798 TaskScheduler::GetInstance()->Shutdown(); | 786 TaskScheduler::GetInstance()->Shutdown(); |
| 799 | 787 |
| 800 // The task should not have completed yet. | 788 // The task should not have completed yet. |
| 801 EXPECT_EQ(0u, tracker()->WaitUntilTasksComplete(0).size()); | 789 EXPECT_EQ(0u, tracker()->WaitUntilTasksComplete(0).size()); |
| 802 | 790 |
| 803 // Posting more tasks should fail. | 791 // Posting more tasks should fail. |
| 804 EXPECT_FALSE(pool()->PostWorkerTaskWithShutdownBehavior( | 792 EXPECT_FALSE(pool()->PostWorkerTaskWithShutdownBehavior( |
| 805 FROM_HERE, base::Bind(&TestTracker::FastTask, tracker(), 0), | 793 FROM_HERE, base::BindOnce(&TestTracker::FastTask, tracker(), 0), |
| 806 SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)); | 794 SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)); |
| 807 EXPECT_FALSE(runner->PostTask( | 795 EXPECT_FALSE(runner->PostTask( |
| 808 FROM_HERE, base::Bind(&TestTracker::FastTask, tracker(), 0))); | 796 FROM_HERE, base::BindOnce(&TestTracker::FastTask, tracker(), 0))); |
| 809 EXPECT_FALSE(sequenced_runner->PostTask( | 797 EXPECT_FALSE(sequenced_runner->PostTask( |
| 810 FROM_HERE, base::Bind(&TestTracker::FastTask, tracker(), 0))); | 798 FROM_HERE, base::BindOnce(&TestTracker::FastTask, tracker(), 0))); |
| 811 | 799 |
| 812 // Continue the background thread and make sure the tasks can complete. | 800 // Continue the background thread and make sure the tasks can complete. |
| 813 blocker.Unblock(3); | 801 blocker.Unblock(3); |
| 814 std::vector<int> result = tracker()->WaitUntilTasksComplete(3); | 802 std::vector<int> result = tracker()->WaitUntilTasksComplete(3); |
| 815 EXPECT_EQ(3u, result.size()); | 803 EXPECT_EQ(3u, result.size()); |
| 816 } | 804 } |
| 817 | 805 |
| 818 // Tests that SKIP_ON_SHUTDOWN tasks that have been started block Shutdown | 806 // Tests that SKIP_ON_SHUTDOWN tasks that have been started block Shutdown |
| 819 // until they stop, but tasks not yet started do not. | 807 // until they stop, but tasks not yet started do not. |
| 820 TEST_P(SequencedWorkerPoolTest, SkipOnShutdown) { | 808 TEST_P(SequencedWorkerPoolTest, SkipOnShutdown) { |
| 821 // As tested by | 809 // As tested by |
| 822 // TaskSchedulerTaskTrackerTest.WillPostAndRunLongTaskBeforeShutdown and | 810 // TaskSchedulerTaskTrackerTest.WillPostAndRunLongTaskBeforeShutdown and |
| 823 // TaskSchedulerTaskTrackerTest.WillPostBeforeShutdownRunDuringShutdown, the | 811 // TaskSchedulerTaskTrackerTest.WillPostBeforeShutdownRunDuringShutdown, the |
| 824 // TaskScheduler correctly handles SKIP_ON_SHUTDOWN tasks. However, since it | 812 // TaskScheduler correctly handles SKIP_ON_SHUTDOWN tasks. However, since it |
| 825 // doesn't provide a way to run a callback from inside its Shutdown() method, | 813 // doesn't provide a way to run a callback from inside its Shutdown() method, |
| 826 // it would be hard to make this test work with redirection enabled. | 814 // it would be hard to make this test work with redirection enabled. |
| 827 if (RedirectedToTaskScheduler()) | 815 if (RedirectedToTaskScheduler()) |
| 828 return; | 816 return; |
| 829 | 817 |
| 830 // Start tasks to take all the threads and block them. | 818 // Start tasks to take all the threads and block them. |
| 831 EnsureAllWorkersCreated(); | 819 EnsureAllWorkersCreated(); |
| 832 ThreadBlocker blocker; | 820 ThreadBlocker blocker; |
| 833 | 821 |
| 834 // Now block all the threads with SKIP_ON_SHUTDOWN. Shutdown() should not | 822 // Now block all the threads with SKIP_ON_SHUTDOWN. Shutdown() should not |
| 835 // return until these tasks have completed. | 823 // return until these tasks have completed. |
| 836 for (size_t i = 0; i < kNumWorkerThreads; i++) { | 824 for (size_t i = 0; i < kNumWorkerThreads; i++) { |
| 837 pool()->PostWorkerTaskWithShutdownBehavior( | 825 pool()->PostWorkerTaskWithShutdownBehavior( |
| 838 FROM_HERE, | 826 FROM_HERE, |
| 839 base::Bind(&TestTracker::BlockTask, tracker(), i, &blocker), | 827 base::BindOnce(&TestTracker::BlockTask, tracker(), i, &blocker), |
| 840 SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 828 SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 841 } | 829 } |
| 842 tracker()->WaitUntilTasksBlocked(kNumWorkerThreads); | 830 tracker()->WaitUntilTasksBlocked(kNumWorkerThreads); |
| 843 | 831 |
| 844 // Now post an additional task as SKIP_ON_SHUTDOWN, which should not be | 832 // Now post an additional task as SKIP_ON_SHUTDOWN, which should not be |
| 845 // executed once Shutdown() has been called. | 833 // executed once Shutdown() has been called. |
| 846 pool()->PostWorkerTaskWithShutdownBehavior( | 834 pool()->PostWorkerTaskWithShutdownBehavior( |
| 847 FROM_HERE, | 835 FROM_HERE, |
| 848 base::Bind(&TestTracker::BlockTask, | 836 base::BindOnce(&TestTracker::BlockTask, tracker(), 0, &blocker), |
| 849 tracker(), 0, &blocker), | |
| 850 SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 837 SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 851 | 838 |
| 852 // This callback will only be invoked if SKIP_ON_SHUTDOWN tasks that have | 839 // This callback will only be invoked if SKIP_ON_SHUTDOWN tasks that have |
| 853 // been started block shutdown. | 840 // been started block shutdown. |
| 854 SetWillWaitForShutdownCallback( | 841 SetWillWaitForShutdownCallback( |
| 855 base::Bind(&EnsureTasksToCompleteCountAndUnblock, | 842 base::Bind(&EnsureTasksToCompleteCountAndUnblock, |
| 856 scoped_refptr<TestTracker>(tracker()), 0, | 843 scoped_refptr<TestTracker>(tracker()), 0, |
| 857 &blocker, kNumWorkerThreads)); | 844 &blocker, kNumWorkerThreads)); |
| 858 | 845 |
| 859 // No tasks should have completed yet. | 846 // No tasks should have completed yet. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 EXPECT_FALSE(unsequenced_task_runner->RunsTasksOnCurrentThread()); | 914 EXPECT_FALSE(unsequenced_task_runner->RunsTasksOnCurrentThread()); |
| 928 EXPECT_FALSE(unused_pool_owner.pool()->RunsTasksOnCurrentThread()); | 915 EXPECT_FALSE(unused_pool_owner.pool()->RunsTasksOnCurrentThread()); |
| 929 | 916 |
| 930 // From a task posted to |sequenced_task_runner_1|: | 917 // From a task posted to |sequenced_task_runner_1|: |
| 931 // - sequenced_task_runner_1->RunsTasksOnCurrentThread() returns true. | 918 // - sequenced_task_runner_1->RunsTasksOnCurrentThread() returns true. |
| 932 // - sequenced_task_runner_2->RunsTasksOnCurrentThread() returns false. | 919 // - sequenced_task_runner_2->RunsTasksOnCurrentThread() returns false. |
| 933 // - pool()->RunsTasksOnCurrentThread() returns true. | 920 // - pool()->RunsTasksOnCurrentThread() returns true. |
| 934 // - unused_pool_owner.pool()->RunsTasksOnCurrentThread() returns false. | 921 // - unused_pool_owner.pool()->RunsTasksOnCurrentThread() returns false. |
| 935 sequenced_task_runner_1->PostTask( | 922 sequenced_task_runner_1->PostTask( |
| 936 FROM_HERE, | 923 FROM_HERE, |
| 937 base::Bind(&VerifyRunsTasksOnCurrentThread, RedirectedToTaskScheduler(), | 924 base::BindOnce(&VerifyRunsTasksOnCurrentThread, |
| 938 sequenced_task_runner_1, sequenced_task_runner_2, | 925 RedirectedToTaskScheduler(), sequenced_task_runner_1, |
| 939 base::RetainedRef(pool()), | 926 sequenced_task_runner_2, base::RetainedRef(pool()), |
| 940 base::RetainedRef(unused_pool_owner.pool()))); | 927 base::RetainedRef(unused_pool_owner.pool()))); |
| 941 // From a task posted to |unsequenced_task_runner|: | 928 // From a task posted to |unsequenced_task_runner|: |
| 942 // - unsequenced_task_runner->RunsTasksOnCurrentThread() returns true. | 929 // - unsequenced_task_runner->RunsTasksOnCurrentThread() returns true. |
| 943 // - sequenced_task_runner_1->RunsTasksOnCurrentThread() returns false. | 930 // - sequenced_task_runner_1->RunsTasksOnCurrentThread() returns false. |
| 944 // - pool()->RunsTasksOnCurrentThread() returns true. | 931 // - pool()->RunsTasksOnCurrentThread() returns true. |
| 945 // - unused_pool_owner.pool()->RunsTasksOnCurrentThread() returns false. | 932 // - unused_pool_owner.pool()->RunsTasksOnCurrentThread() returns false. |
| 946 unsequenced_task_runner->PostTask( | 933 unsequenced_task_runner->PostTask( |
| 947 FROM_HERE, | 934 FROM_HERE, |
| 948 base::Bind(&VerifyRunsTasksOnCurrentThread, RedirectedToTaskScheduler(), | 935 base::BindOnce(&VerifyRunsTasksOnCurrentThread, |
| 949 unsequenced_task_runner, sequenced_task_runner_1, | 936 RedirectedToTaskScheduler(), unsequenced_task_runner, |
| 950 base::RetainedRef(pool()), | 937 sequenced_task_runner_1, base::RetainedRef(pool()), |
| 951 base::RetainedRef(unused_pool_owner.pool()))); | 938 base::RetainedRef(unused_pool_owner.pool()))); |
| 952 } | 939 } |
| 953 | 940 |
| 954 // Checks that tasks are destroyed in the right context during shutdown. If a | 941 // Checks that tasks are destroyed in the right context during shutdown. If a |
| 955 // task is destroyed while SequencedWorkerPool's global lock is held, | 942 // task is destroyed while SequencedWorkerPool's global lock is held, |
| 956 // SequencedWorkerPool might deadlock. | 943 // SequencedWorkerPool might deadlock. |
| 957 TEST_P(SequencedWorkerPoolTest, AvoidsDeadlockOnShutdown) { | 944 TEST_P(SequencedWorkerPoolTest, AvoidsDeadlockOnShutdown) { |
| 958 // Note: TaskScheduler destroys tasks when it is deleted rather than on | 945 // Note: TaskScheduler destroys tasks when it is deleted rather than on |
| 959 // shutdown. In production, it should never be destroyed. | 946 // shutdown. In production, it should never be destroyed. |
| 960 | 947 |
| 961 for (int i = 0; i < 4; ++i) { | 948 for (int i = 0; i < 4; ++i) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 } | 984 } |
| 998 | 985 |
| 999 // Verify that FlushForTesting works as intended. | 986 // Verify that FlushForTesting works as intended. |
| 1000 TEST_P(SequencedWorkerPoolTest, FlushForTesting) { | 987 TEST_P(SequencedWorkerPoolTest, FlushForTesting) { |
| 1001 // Should be fine to call on a new instance. | 988 // Should be fine to call on a new instance. |
| 1002 pool()->FlushForTesting(); | 989 pool()->FlushForTesting(); |
| 1003 | 990 |
| 1004 // Queue up a bunch of work, including a long delayed task and | 991 // Queue up a bunch of work, including a long delayed task and |
| 1005 // a task that produces additional tasks as an artifact. | 992 // a task that produces additional tasks as an artifact. |
| 1006 pool()->PostDelayedWorkerTask( | 993 pool()->PostDelayedWorkerTask( |
| 1007 FROM_HERE, | 994 FROM_HERE, base::BindOnce(&TestTracker::FastTask, tracker(), 0), |
| 1008 base::Bind(&TestTracker::FastTask, tracker(), 0), | |
| 1009 TimeDelta::FromMinutes(5)); | 995 TimeDelta::FromMinutes(5)); |
| 1010 pool()->PostWorkerTask(FROM_HERE, | 996 pool()->PostWorkerTask(FROM_HERE, |
| 1011 base::Bind(&TestTracker::SlowTask, tracker(), 0)); | 997 base::BindOnce(&TestTracker::SlowTask, tracker(), 0)); |
| 1012 const size_t kNumFastTasks = 20; | 998 const size_t kNumFastTasks = 20; |
| 1013 for (size_t i = 0; i < kNumFastTasks; i++) { | 999 for (size_t i = 0; i < kNumFastTasks; i++) { |
| 1014 pool()->PostWorkerTask(FROM_HERE, | 1000 pool()->PostWorkerTask( |
| 1015 base::Bind(&TestTracker::FastTask, tracker(), 0)); | 1001 FROM_HERE, base::BindOnce(&TestTracker::FastTask, tracker(), 0)); |
| 1016 } | 1002 } |
| 1017 pool()->PostWorkerTask( | 1003 pool()->PostWorkerTask( |
| 1018 FROM_HERE, base::Bind(&TestTracker::PostAdditionalTasks, tracker(), 0, | 1004 FROM_HERE, base::BindOnce(&TestTracker::PostAdditionalTasks, tracker(), 0, |
| 1019 base::RetainedRef(pool()), true)); | 1005 base::RetainedRef(pool()), true)); |
| 1020 | 1006 |
| 1021 // We expect all except the delayed task to have been run. We verify all | 1007 // We expect all except the delayed task to have been run. We verify all |
| 1022 // closures have been deleted by looking at the refcount of the | 1008 // closures have been deleted by looking at the refcount of the |
| 1023 // tracker. | 1009 // tracker. |
| 1024 EXPECT_FALSE(tracker()->HasOneRef()); | 1010 EXPECT_FALSE(tracker()->HasOneRef()); |
| 1025 pool()->FlushForTesting(); | 1011 pool()->FlushForTesting(); |
| 1026 EXPECT_EQ(1 + kNumFastTasks + 1 + 3, tracker()->GetTasksCompletedCount()); | 1012 EXPECT_EQ(1 + kNumFastTasks + 1 + 3, tracker()->GetTasksCompletedCount()); |
| 1027 // TaskScheduler deletes unexecuted delayed tasks as part of ~TaskScheduler() | 1013 // TaskScheduler deletes unexecuted delayed tasks as part of ~TaskScheduler() |
| 1028 // instead of TaskScheduler::FlushForTesting(). | 1014 // instead of TaskScheduler::FlushForTesting(). |
| 1029 EXPECT_EQ(!RedirectedToTaskScheduler(), tracker()->HasOneRef()); | 1015 EXPECT_EQ(!RedirectedToTaskScheduler(), tracker()->HasOneRef()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1079 SequencedWorkerPool::GetSequenceTokenForCurrentThread(); | 1065 SequencedWorkerPool::GetSequenceTokenForCurrentThread(); |
| 1080 scoped_refptr<SequencedWorkerPool> local_pool = | 1066 scoped_refptr<SequencedWorkerPool> local_pool = |
| 1081 SequencedWorkerPool::GetWorkerPoolForCurrentThread(); | 1067 SequencedWorkerPool::GetWorkerPoolForCurrentThread(); |
| 1082 EXPECT_FALSE(local_token.IsValid()) << local_token.ToString(); | 1068 EXPECT_FALSE(local_token.IsValid()) << local_token.ToString(); |
| 1083 EXPECT_FALSE(local_pool); | 1069 EXPECT_FALSE(local_pool); |
| 1084 | 1070 |
| 1085 SequencedWorkerPool::SequenceToken token1 = pool()->GetSequenceToken(); | 1071 SequencedWorkerPool::SequenceToken token1 = pool()->GetSequenceToken(); |
| 1086 SequencedWorkerPool::SequenceToken token2 = pool()->GetSequenceToken(); | 1072 SequencedWorkerPool::SequenceToken token2 = pool()->GetSequenceToken(); |
| 1087 pool()->PostSequencedWorkerTask( | 1073 pool()->PostSequencedWorkerTask( |
| 1088 token1, FROM_HERE, | 1074 token1, FROM_HERE, |
| 1089 base::Bind(&CheckWorkerPoolAndSequenceToken, pool(), token1)); | 1075 base::BindOnce(&CheckWorkerPoolAndSequenceToken, pool(), token1)); |
| 1090 pool()->PostSequencedWorkerTask( | 1076 pool()->PostSequencedWorkerTask( |
| 1091 token2, FROM_HERE, | 1077 token2, FROM_HERE, |
| 1092 base::Bind(&CheckWorkerPoolAndSequenceToken, pool(), token2)); | 1078 base::BindOnce(&CheckWorkerPoolAndSequenceToken, pool(), token2)); |
| 1093 | 1079 |
| 1094 pool()->PostWorkerTask(FROM_HERE, | 1080 pool()->PostWorkerTask( |
| 1095 base::Bind(&CheckWorkerPoolAndSequenceToken, pool(), | 1081 FROM_HERE, base::BindOnce(&CheckWorkerPoolAndSequenceToken, pool(), |
| 1096 SequencedWorkerPool::SequenceToken())); | 1082 SequencedWorkerPool::SequenceToken())); |
| 1097 | 1083 |
| 1098 pool()->FlushForTesting(); | 1084 pool()->FlushForTesting(); |
| 1099 } | 1085 } |
| 1100 | 1086 |
| 1101 TEST_P(SequencedWorkerPoolTest, ShutsDownCleanWithContinueOnShutdown) { | 1087 TEST_P(SequencedWorkerPoolTest, ShutsDownCleanWithContinueOnShutdown) { |
| 1102 scoped_refptr<SequencedTaskRunner> task_runner = | 1088 scoped_refptr<SequencedTaskRunner> task_runner = |
| 1103 pool()->GetSequencedTaskRunnerWithShutdownBehavior( | 1089 pool()->GetSequencedTaskRunnerWithShutdownBehavior( |
| 1104 pool()->GetSequenceToken(), | 1090 pool()->GetSequenceToken(), |
| 1105 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 1091 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
| 1106 | 1092 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1236 SequencedWorkerPoolSequencedTaskRunner, SequencedTaskRunnerTest, | 1222 SequencedWorkerPoolSequencedTaskRunner, SequencedTaskRunnerTest, |
| 1237 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); | 1223 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); |
| 1238 INSTANTIATE_TYPED_TEST_CASE_P( | 1224 INSTANTIATE_TYPED_TEST_CASE_P( |
| 1239 SequencedWorkerPoolSequencedTaskRunner, | 1225 SequencedWorkerPoolSequencedTaskRunner, |
| 1240 SequencedTaskRunnerDelayedTest, | 1226 SequencedTaskRunnerDelayedTest, |
| 1241 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); | 1227 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); |
| 1242 | 1228 |
| 1243 } // namespace | 1229 } // namespace |
| 1244 | 1230 |
| 1245 } // namespace base | 1231 } // namespace base |
| OLD | NEW |