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

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

Issue 2531883002: TaskScheduler: Set the IO allowed bit in TaskTracker::RunTask(). (Closed)
Patch Set: CR robliao #22 (reorder reset) Created 4 years 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/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 <utility> 10 #include <utility>
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 424
425 // Running the task should fail iff the task isn't allowed to use singletons. 425 // Running the task should fail iff the task isn't allowed to use singletons.
426 if (can_use_singletons) { 426 if (can_use_singletons) {
427 EXPECT_TRUE(tracker.RunTask(std::move(task), SequenceToken::Create())); 427 EXPECT_TRUE(tracker.RunTask(std::move(task), SequenceToken::Create()));
428 } else { 428 } else {
429 EXPECT_DCHECK_DEATH( 429 EXPECT_DCHECK_DEATH(
430 { tracker.RunTask(std::move(task), SequenceToken::Create()); }); 430 { tracker.RunTask(std::move(task), SequenceToken::Create()); });
431 } 431 }
432 } 432 }
433 433
434 // Verify that AssertIOAllowed() succeeds only for a WithFileIO() task.
435 TEST_P(TaskSchedulerTaskTrackerTest, IOAllowed) {
436 TaskTracker tracker;
437
438 // Unset the IO allowed bit. Expect TaskTracker to set it before running a
439 // task with the WithFileIO() trait.
440 ThreadRestrictions::SetIOAllowed(false);
441 auto task_with_file_io = MakeUnique<Task>(
442 FROM_HERE, Bind([]() {
443 // Shouldn't fail.
444 ThreadRestrictions::AssertIOAllowed();
445 }),
446 TaskTraits().WithFileIO().WithShutdownBehavior(GetParam()), TimeDelta());
447 EXPECT_TRUE(tracker.WillPostTask(task_with_file_io.get()));
448 tracker.RunTask(std::move(task_with_file_io), SequenceToken::Create());
449
450 // Set the IO allowed bit. Expect TaskTracker to unset it before running a
451 // task without the WithFileIO() trait.
452 ThreadRestrictions::SetIOAllowed(true);
453 auto task_without_file_io = MakeUnique<Task>(
454 FROM_HERE, Bind([]() {
455 EXPECT_DCHECK_DEATH({ ThreadRestrictions::AssertIOAllowed(); });
456 }),
457 TaskTraits().WithShutdownBehavior(GetParam()), TimeDelta());
458 EXPECT_TRUE(tracker.WillPostTask(task_without_file_io.get()));
459 tracker.RunTask(std::move(task_without_file_io), SequenceToken::Create());
460 }
461
434 static void RunTaskRunnerHandleVerificationTask( 462 static void RunTaskRunnerHandleVerificationTask(
435 TaskTracker* tracker, 463 TaskTracker* tracker,
436 std::unique_ptr<Task> verify_task) { 464 std::unique_ptr<Task> verify_task) {
437 // Pretend |verify_task| is posted to respect TaskTracker's contract. 465 // Pretend |verify_task| is posted to respect TaskTracker's contract.
438 EXPECT_TRUE(tracker->WillPostTask(verify_task.get())); 466 EXPECT_TRUE(tracker->WillPostTask(verify_task.get()));
439 467
440 // Confirm that the test conditions are right (no TaskRunnerHandles set 468 // Confirm that the test conditions are right (no TaskRunnerHandles set
441 // already). 469 // already).
442 EXPECT_FALSE(ThreadTaskRunnerHandle::IsSet()); 470 EXPECT_FALSE(ThreadTaskRunnerHandle::IsSet());
443 EXPECT_FALSE(SequencedTaskRunnerHandle::IsSet()); 471 EXPECT_FALSE(SequencedTaskRunnerHandle::IsSet());
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 827
800 // Unblock shutdown by running |block_shutdown_task|. 828 // Unblock shutdown by running |block_shutdown_task|.
801 EXPECT_TRUE(tracker_.RunTask(std::move(block_shutdown_task), 829 EXPECT_TRUE(tracker_.RunTask(std::move(block_shutdown_task),
802 SequenceToken::Create())); 830 SequenceToken::Create()));
803 EXPECT_EQ(kLoadTestNumIterations + 1, NumTasksExecuted()); 831 EXPECT_EQ(kLoadTestNumIterations + 1, NumTasksExecuted());
804 WAIT_FOR_ASYNC_SHUTDOWN_COMPLETED(); 832 WAIT_FOR_ASYNC_SHUTDOWN_COMPLETED();
805 } 833 }
806 834
807 } // namespace internal 835 } // namespace internal
808 } // namespace base 836 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698