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

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

Issue 2857103005: Exempt the Service Thread from BLOCK_SHUTDOWN DCHECKs (Closed)
Patch Set: Created 3 years, 7 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
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_scheduler_impl.h" 5 #include "base/task_scheduler/task_scheduler_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/synchronization/lock.h" 18 #include "base/synchronization/lock.h"
19 #include "base/synchronization/waitable_event.h" 19 #include "base/synchronization/waitable_event.h"
20 #include "base/task_scheduler/scheduler_worker_pool_params.h" 20 #include "base/task_scheduler/scheduler_worker_pool_params.h"
21 #include "base/task_scheduler/task_traits.h" 21 #include "base/task_scheduler/task_traits.h"
22 #include "base/task_scheduler/test_task_factory.h" 22 #include "base/task_scheduler/test_task_factory.h"
23 #include "base/test/test_timeouts.h" 23 #include "base/test/test_timeouts.h"
24 #include "base/threading/platform_thread.h" 24 #include "base/threading/platform_thread.h"
25 #include "base/threading/simple_thread.h" 25 #include "base/threading/simple_thread.h"
26 #include "base/threading/thread.h" 26 #include "base/threading/thread.h"
27 #include "base/threading/thread_restrictions.h" 27 #include "base/threading/thread_restrictions.h"
28 #include "base/time/time.h" 28 #include "base/time/time.h"
29 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
fdoray 2017/05/03 20:34:33 #include "build/build_config.h"
robliao 2017/05/03 21:11:17 Done.
30 30
31 #if defined(OS_POSIX)
32 #include <unistd.h>
33
34 #include "base/debug/leak_annotations.h"
35 #include "base/files/file_descriptor_watcher_posix.h"
36 #include "base/files/file_util.h"
37 #include "base/posix/eintr_wrapper.h"
38 #endif // defined(OS_POSIX)
39
31 #if defined(OS_WIN) 40 #if defined(OS_WIN)
32 #include <objbase.h> 41 #include <objbase.h>
33 #endif // defined(OS_WIN) 42 #endif // defined(OS_WIN)
34 43
35 namespace base { 44 namespace base {
36 namespace internal { 45 namespace internal {
37 46
38 namespace { 47 namespace {
39 48
40 struct TraitsExecutionModePair { 49 struct TraitsExecutionModePair {
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 ADD_FAILURE() << "COM STA was not initialized on this thread"; 449 ADD_FAILURE() << "COM STA was not initialized on this thread";
441 CoUninitialize(); 450 CoUninitialize();
442 } 451 }
443 task_ran->Signal(); 452 task_ran->Signal();
444 }, 453 },
445 com_sta_task_runner, Unretained(&task_ran))); 454 com_sta_task_runner, Unretained(&task_ran)));
446 task_ran.Wait(); 455 task_ran.Wait();
447 } 456 }
448 #endif // defined(OS_WIN) 457 #endif // defined(OS_WIN)
449 458
459 TEST_F(TaskSchedulerImplTest, DelayedTasksNotRunAfterShutdown) {
460 StartTaskScheduler();
461 scheduler_.PostDelayedTaskWithTraits(FROM_HERE, TaskTraits(),
fdoray 2017/05/03 20:34:33 Comment that this is racy or make it non-racy. Po
robliao 2017/05/03 21:11:17 Seems like the barrier just ensures that a task ac
fdoray 2017/05/04 18:37:32 In the current state, the test may fail if the 50
robliao 2017/05/04 19:01:48 Discussed offline. Shutdown() would block, which m
462 BindOnce([]() { ADD_FAILURE(); }),
463 TimeDelta::FromMilliseconds(50));
fdoray 2017/05/03 20:34:33 TestTimeouts::tiny_timeout() here and 2*TestTimeou
robliao 2017/05/03 21:11:17 Done.
464 scheduler_.Shutdown();
465 PlatformThread::Sleep(TimeDelta::FromMilliseconds(100));
466 }
467
468 #if defined(OS_POSIX)
469
470 TEST_F(TaskSchedulerImplTest, FileDescriptorWatcherNoOpsAfterShutdown) {
471 StartTaskScheduler();
472
473 int pipes[2];
474 ASSERT_EQ(0, pipe(pipes));
475
476 scoped_refptr<TaskRunner> blocking_task_runner =
477 scheduler_.CreateSequencedTaskRunnerWithTraits(
478 TaskTraits().WithShutdownBehavior(
479 TaskShutdownBehavior::BLOCK_SHUTDOWN));
480 blocking_task_runner->PostTask(
481 FROM_HERE,
482 BindOnce(
483 [](int read_fd) {
484 std::unique_ptr<FileDescriptorWatcher::Controller> controller =
485 FileDescriptorWatcher::WatchReadable(
486 read_fd, BindRepeating([]() { NOTREACHED(); }));
487
488 // This test is for components that intentionally leak their
489 // watchers at shutdown. We can't clean |controller| up because its
490 // destructor will assert that it's being called from the correct
491 // sequence. After the task scheduler is shutdown, it is not
492 // possible to run tasks on this sequence.
493 ANNOTATE_LEAKING_OBJECT_PTR(controller.get());
494 controller.release();
495 },
496 pipes[0]));
497
498 scheduler_.Shutdown();
499
500 constexpr char kByte = '!';
501 ASSERT_TRUE(WriteFileDescriptor(pipes[1], &kByte, sizeof(kByte)));
502
503 // Give a chance for the file watcher to fire before closing the handles.
504 PlatformThread::Sleep(TimeDelta::FromMilliseconds(100));
505
506 EXPECT_EQ(0, IGNORE_EINTR(close(pipes[0])));
507 EXPECT_EQ(0, IGNORE_EINTR(close(pipes[1])));
508 }
509 #endif // defined(OS_POSIX)
510
450 } // namespace internal 511 } // namespace internal
451 } // namespace base 512 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698