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

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

Issue 2215193003: DO NOT COMMIT -- Very confusing patch... (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@b1_dcheckfailedcatch
Patch Set: rebase Created 4 years, 4 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_tracker.cc ('k') | no next file » | 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 <vector> 10 #include <vector>
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 const Action action_; 104 const Action action_;
105 const bool expect_post_succeeds_; 105 const bool expect_post_succeeds_;
106 106
107 DISALLOW_COPY_AND_ASSIGN(ThreadPostingAndRunningTask); 107 DISALLOW_COPY_AND_ASSIGN(ThreadPostingAndRunningTask);
108 }; 108 };
109 109
110 class ScopedSetSingletonAllowed { 110 class ScopedSetSingletonAllowed {
111 public: 111 public:
112 ScopedSetSingletonAllowed(bool singleton_allowed) 112 ScopedSetSingletonAllowed(bool singleton_allowed)
113 : previous_value_( 113 : previous_value_(
114 ThreadRestrictions::SetSingletonAllowed(singleton_allowed)) {} 114 ThreadRestrictions::SetIOAllowed(singleton_allowed)) {}
115 ~ScopedSetSingletonAllowed() { 115 ~ScopedSetSingletonAllowed() {
116 ThreadRestrictions::SetSingletonAllowed(previous_value_); 116 ThreadRestrictions::SetIOAllowed(previous_value_);
117 } 117 }
118 118
119 private: 119 private:
120 const bool previous_value_; 120 const bool previous_value_;
121 }; 121 };
122 122
123 class TaskSchedulerTaskTrackerTest 123 class TaskSchedulerTaskTrackerTest
124 : public testing::TestWithParam<TaskShutdownBehavior> { 124 : public testing::TestWithParam<TaskShutdownBehavior> {
125 protected: 125 protected:
126 TaskSchedulerTaskTrackerTest() = default; 126 TaskSchedulerTaskTrackerTest() = default;
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 } 361 }
362 362
363 // Verify that BLOCK_SHUTDOWN and SKIP_ON_SHUTDOWN tasks can 363 // Verify that BLOCK_SHUTDOWN and SKIP_ON_SHUTDOWN tasks can
364 // AssertSingletonAllowed() but CONTINUE_ON_SHUTDOWN tasks can't. 364 // AssertSingletonAllowed() but CONTINUE_ON_SHUTDOWN tasks can't.
365 TEST_P(TaskSchedulerTaskTrackerTest, SingletonAllowed) { 365 TEST_P(TaskSchedulerTaskTrackerTest, SingletonAllowed) {
366 const bool can_use_singletons = 366 const bool can_use_singletons =
367 (GetParam() != TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); 367 (GetParam() != TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN);
368 368
369 TaskTracker tracker; 369 TaskTracker tracker;
370 std::unique_ptr<Task> task( 370 std::unique_ptr<Task> task(
371 new Task(FROM_HERE, Bind(&ThreadRestrictions::AssertSingletonAllowed), 371 new Task(FROM_HERE, Bind(&ThreadRestrictions::AssertIOAllowed),
372 TaskTraits().WithShutdownBehavior(GetParam()), TimeDelta())); 372 TaskTraits().WithShutdownBehavior(GetParam()), TimeDelta()));
373 EXPECT_TRUE(tracker.WillPostTask(task.get())); 373 EXPECT_TRUE(tracker.WillPostTask(task.get()));
374 374
375 // Set the singleton allowed bit to the opposite of what it is expected to be 375 // Set the singleton allowed bit to the opposite of what it is expected to be
376 // when |tracker| runs |task| to verify that |tracker| actually sets the 376 // when |tracker| runs |task| to verify that |tracker| actually sets the
377 // correct value. 377 // correct value.
378 ScopedSetSingletonAllowed scoped_singleton_allowed(!can_use_singletons); 378 ScopedSetSingletonAllowed scoped_singleton_allowed(!can_use_singletons);
379 379
380 // Running the task should fail iff the task isn't allowed to use singletons. 380 // Running the task should fail iff the task isn't allowed to use singletons.
381 if (can_use_singletons) { 381 if (can_use_singletons) {
382 tracker.RunNextTaskInSequence( 382 tracker.RunNextTaskInSequence(
383 CreateSequenceWithTask(std::move(task)).get()); 383 CreateSequenceWithTask(std::move(task)).get());
384 } else { 384 } else {
385 #if !defined(OS_LINUX) // http://crbug.com/634552
386 EXPECT_DCHECK_DEATH( 385 EXPECT_DCHECK_DEATH(
387 { 386 {
388 tracker.RunNextTaskInSequence( 387 tracker.RunNextTaskInSequence(
389 CreateSequenceWithTask(std::move(task)).get()); 388 CreateSequenceWithTask(std::move(task)).get());
390 }); 389 });
391 #endif // !defined(OS_LINUX)
392 } 390 }
393 } 391 }
394 392
395 static void RunTaskRunnerHandleVerificationTask( 393 static void RunTaskRunnerHandleVerificationTask(
396 TaskTracker* tracker, 394 TaskTracker* tracker,
397 std::unique_ptr<Task> verify_task) { 395 std::unique_ptr<Task> verify_task) {
398 // Pretend |verify_task| is posted to respect TaskTracker's contract. 396 // Pretend |verify_task| is posted to respect TaskTracker's contract.
399 EXPECT_TRUE(tracker->WillPostTask(verify_task.get())); 397 EXPECT_TRUE(tracker->WillPostTask(verify_task.get()));
400 398
401 // Confirm that the test conditions are right (no TaskRunnerHandles set 399 // Confirm that the test conditions are right (no TaskRunnerHandles set
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 638
641 // Unblock shutdown by running |block_shutdown_task|. 639 // Unblock shutdown by running |block_shutdown_task|.
642 tracker_.RunNextTaskInSequence( 640 tracker_.RunNextTaskInSequence(
643 CreateSequenceWithTask(std::move(block_shutdown_task)).get()); 641 CreateSequenceWithTask(std::move(block_shutdown_task)).get());
644 EXPECT_EQ(kLoadTestNumIterations + 1, NumTasksExecuted()); 642 EXPECT_EQ(kLoadTestNumIterations + 1, NumTasksExecuted());
645 WAIT_FOR_ASYNC_SHUTDOWN_COMPLETED(); 643 WAIT_FOR_ASYNC_SHUTDOWN_COMPLETED();
646 } 644 }
647 645
648 } // namespace internal 646 } // namespace internal
649 } // namespace base 647 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/task_tracker.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698