Commit d6f41f97 authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

[base] Enable FileDescriptorWatcher under IO_MOCK_TIME too

R=fdoray@chromium.org

Bug: 708584
Change-Id: I3d51b3e1b567974805d255cc1300d1b0baf49ebb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1594914
Auto-Submit: Gabriel Charette <gab@chromium.org>
Reviewed-by: default avatarAlex Clarke <alexclarke@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Commit-Queue: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#656474}
parent 0713fb9e
...@@ -416,7 +416,8 @@ void ScopedTaskEnvironment::InitializeThreadPool() { ...@@ -416,7 +416,8 @@ void ScopedTaskEnvironment::InitializeThreadPool() {
void ScopedTaskEnvironment::CompleteInitialization() { void ScopedTaskEnvironment::CompleteInitialization() {
#if defined(OS_POSIX) || defined(OS_FUCHSIA) #if defined(OS_POSIX) || defined(OS_FUCHSIA)
if (main_thread_type() == MainThreadType::IO) { if (main_thread_type() == MainThreadType::IO ||
main_thread_type() == MainThreadType::IO_MOCK_TIME) {
file_descriptor_watcher_ = file_descriptor_watcher_ =
std::make_unique<FileDescriptorWatcher>(GetMainThreadTaskRunner()); std::make_unique<FileDescriptorWatcher>(GetMainThreadTaskRunner());
} }
......
...@@ -287,8 +287,7 @@ TEST_P(ScopedTaskEnvironmentTest, SingleThreadShouldNotInitializeThreadPool) { ...@@ -287,8 +287,7 @@ TEST_P(ScopedTaskEnvironmentTest, SingleThreadShouldNotInitializeThreadPool) {
#if defined(OS_POSIX) #if defined(OS_POSIX)
TEST_F(ScopedTaskEnvironmentTest, SupportsFileDescriptorWatcherOnIOMainThread) { TEST_F(ScopedTaskEnvironmentTest, SupportsFileDescriptorWatcherOnIOMainThread) {
ScopedTaskEnvironment scoped_task_environment( ScopedTaskEnvironment scoped_task_environment(
ScopedTaskEnvironment::MainThreadType::IO, ScopedTaskEnvironment::MainThreadType::IO);
ScopedTaskEnvironment::ThreadPoolExecutionMode::ASYNC);
int pipe_fds_[2]; int pipe_fds_[2];
ASSERT_EQ(0, pipe(pipe_fds_)); ASSERT_EQ(0, pipe(pipe_fds_));
...@@ -302,6 +301,32 @@ TEST_F(ScopedTaskEnvironmentTest, SupportsFileDescriptorWatcherOnIOMainThread) { ...@@ -302,6 +301,32 @@ TEST_F(ScopedTaskEnvironmentTest, SupportsFileDescriptorWatcherOnIOMainThread) {
// This will hang if the notification doesn't occur as expected. // This will hang if the notification doesn't occur as expected.
run_loop.Run(); run_loop.Run();
} }
TEST_F(ScopedTaskEnvironmentTest,
SupportsFileDescriptorWatcherOnIOMockTimeMainThread) {
ScopedTaskEnvironment scoped_task_environment(
ScopedTaskEnvironment::MainThreadType::IO_MOCK_TIME);
int pipe_fds_[2];
ASSERT_EQ(0, pipe(pipe_fds_));
RunLoop run_loop;
ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, BindLambdaForTesting([&]() {
int64_t x = 1;
auto ret = write(pipe_fds_[1], &x, sizeof(x));
ASSERT_EQ(static_cast<size_t>(ret), sizeof(x));
}),
TimeDelta::FromHours(1));
auto controller = FileDescriptorWatcher::WatchReadable(
pipe_fds_[0], run_loop.QuitClosure());
// This will hang if the notification doesn't occur as expected (Run() should
// fast-forward-time when idle).
run_loop.Run();
}
#endif // defined(OS_POSIX) #endif // defined(OS_POSIX)
// Verify that the TickClock returned by // Verify that the TickClock returned by
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment