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

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: rebase 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
« no previous file with comments | « base/task_scheduler/task_tracker.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_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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 // Run the test on the separate thread since it is not possible to reset the 876 // Run the test on the separate thread since it is not possible to reset the
849 // "wait allowed" bit of a thread without being a friend of 877 // "wait allowed" bit of a thread without being a friend of
850 // ThreadRestrictions. 878 // ThreadRestrictions.
851 WaitAllowedTestThread wait_allowed_test_thread; 879 WaitAllowedTestThread wait_allowed_test_thread;
852 wait_allowed_test_thread.Start(); 880 wait_allowed_test_thread.Start();
853 wait_allowed_test_thread.Join(); 881 wait_allowed_test_thread.Join();
854 } 882 }
855 883
856 } // namespace internal 884 } // namespace internal
857 } // namespace base 885 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/task_tracker.cc ('k') | base/test/scoped_task_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698