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

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

Issue 2213933003: Change EXPECT/ASSERT_DCHECK_DEATH macro to not expose the |regex| parameter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@b2b0_simplethreadJoinable
Patch Set: Disabling a death test which crashed instead of DCHECKing : http://crbug.com/634552 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/scheduler_worker_stack_unittest.cc ('k') | base/test/gtest_util.h » ('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 <vector> 10 #include <vector>
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 WAIT_FOR_ASYNC_SHUTDOWN_COMPLETED(); 347 WAIT_FOR_ASYNC_SHUTDOWN_COMPLETED();
348 } 348 }
349 349
350 TEST_P(TaskSchedulerTaskTrackerTest, WillPostAfterShutdown) { 350 TEST_P(TaskSchedulerTaskTrackerTest, WillPostAfterShutdown) {
351 tracker_.Shutdown(); 351 tracker_.Shutdown();
352 352
353 std::unique_ptr<Task> task(CreateTask(GetParam())); 353 std::unique_ptr<Task> task(CreateTask(GetParam()));
354 354
355 // |task_tracker_| shouldn't allow a task to be posted after shutdown. 355 // |task_tracker_| shouldn't allow a task to be posted after shutdown.
356 if (GetParam() == TaskShutdownBehavior::BLOCK_SHUTDOWN) { 356 if (GetParam() == TaskShutdownBehavior::BLOCK_SHUTDOWN) {
357 EXPECT_DCHECK_DEATH({ tracker_.WillPostTask(task.get()); }, ""); 357 EXPECT_DCHECK_DEATH({ tracker_.WillPostTask(task.get()); });
358 } else { 358 } else {
359 EXPECT_FALSE(tracker_.WillPostTask(task.get())); 359 EXPECT_FALSE(tracker_.WillPostTask(task.get()));
360 } 360 }
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::AssertSingletonAllowed),
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
385 EXPECT_DCHECK_DEATH( 386 EXPECT_DCHECK_DEATH(
386 { 387 {
387 tracker.RunNextTaskInSequence( 388 tracker.RunNextTaskInSequence(
388 CreateSequenceWithTask(std::move(task)).get()); 389 CreateSequenceWithTask(std::move(task)).get());
389 }, 390 });
390 ""); 391 #endif // !defined(OS_LINUX)
391 } 392 }
392 } 393 }
393 394
394 static void RunTaskRunnerHandleVerificationTask( 395 static void RunTaskRunnerHandleVerificationTask(
395 TaskTracker* tracker, 396 TaskTracker* tracker,
396 std::unique_ptr<Task> verify_task) { 397 std::unique_ptr<Task> verify_task) {
397 // Pretend |verify_task| is posted to respect TaskTracker's contract. 398 // Pretend |verify_task| is posted to respect TaskTracker's contract.
398 EXPECT_TRUE(tracker->WillPostTask(verify_task.get())); 399 EXPECT_TRUE(tracker->WillPostTask(verify_task.get()));
399 400
400 // Confirm that the test conditions are right (no TaskRunnerHandles set 401 // Confirm that the test conditions are right (no TaskRunnerHandles set
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 640
640 // Unblock shutdown by running |block_shutdown_task|. 641 // Unblock shutdown by running |block_shutdown_task|.
641 tracker_.RunNextTaskInSequence( 642 tracker_.RunNextTaskInSequence(
642 CreateSequenceWithTask(std::move(block_shutdown_task)).get()); 643 CreateSequenceWithTask(std::move(block_shutdown_task)).get());
643 EXPECT_EQ(kLoadTestNumIterations + 1, NumTasksExecuted()); 644 EXPECT_EQ(kLoadTestNumIterations + 1, NumTasksExecuted());
644 WAIT_FOR_ASYNC_SHUTDOWN_COMPLETED(); 645 WAIT_FOR_ASYNC_SHUTDOWN_COMPLETED();
645 } 646 }
646 647
647 } // namespace internal 648 } // namespace internal
648 } // namespace base 649 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/scheduler_worker_stack_unittest.cc ('k') | base/test/gtest_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698