#include "base/task/thread_pool/thread_group.h"
#include <memory>
#include <tuple>
#include <utility>
#include "base/barrier_closure.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/memory/ref_counted.h"
#include "base/task/task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool/can_run_policy_test.h"
#include "base/task/thread_pool/delayed_task_manager.h"
#include "base/task/thread_pool/pooled_sequenced_task_runner.h"
#include "base/task/thread_pool/task_tracker.h"
#include "base/task/thread_pool/test_task_factory.h"
#include "base/task/thread_pool/test_utils.h"
#include "base/task/thread_pool/thread_group_impl.h"
#include "base/test/bind.h"
#include "base/test/test_timeouts.h"
#include "base/test/test_waitable_event.h"
#include "base/threading/platform_thread.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/threading/scoped_blocking_call_internal.h"
#include "base/threading/simple_thread.h"
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(IS_WIN)
#include "base/win/com_init_check_hook.h"
#include "base/win/com_init_util.h"
#endif
namespace base {
namespace internal {
namespace {
constexpr size_t kMaxTasks = …;
constexpr size_t kTooManyTasks = …;
constexpr size_t kMaxBestEffortTasks = …;
constexpr size_t kNumThreadsPostingTasks = …;
constexpr size_t kNumTasksPostedPerThread = …;
PostNestedTask;
class ThreadPostingTasks : public SimpleThread { … };
class ThreadGroupTestBase : public testing::Test, public ThreadGroup::Delegate { … };
ThreadGroupTest;
class ThreadGroupTestAllExecutionModes
: public ThreadGroupTestBase,
public testing::WithParamInterface<TaskSourceExecutionMode> { … };
void ShouldNotRun() { … }
}
TEST_P(ThreadGroupTestAllExecutionModes, PostTasks) { … }
TEST_P(ThreadGroupTestAllExecutionModes, NestedPostTasks) { … }
TEST_P(ThreadGroupTestAllExecutionModes, PostTaskAfterShutdown) { … }
TEST_P(ThreadGroupTestAllExecutionModes, PostDelayedTask) { … }
TEST_P(ThreadGroupTestAllExecutionModes, SequencedRunsTasksInCurrentSequence) { … }
TEST_P(ThreadGroupTestAllExecutionModes, PostBeforeStart) { … }
TEST_P(ThreadGroupTestAllExecutionModes, CanRunPolicyBasic) { … }
TEST_F(ThreadGroupTest, CanRunPolicyUpdatedBeforeRun) { … }
TEST_P(ThreadGroupTestAllExecutionModes, CanRunPolicyLoad) { … }
TEST_F(ThreadGroupTest, CanRunPolicyShouldYield) { … }
TEST_F(ThreadGroupTest, SetMaxTasks) { … }
TEST_F(ThreadGroupTest, UpdatePriorityBestEffortToUserBlocking) { … }
TEST_P(ThreadGroupTestAllExecutionModes, ScopedBlockingCallTwice) { … }
#if BUILDFLAG(IS_WIN)
TEST_P(ThreadGroupTestAllExecutionModes, COMMTAWorkerEnvironment) {
StartThreadGroup(ThreadGroup::WorkerEnvironment::COM_MTA);
auto task_runner = test::CreatePooledTaskRunnerWithExecutionMode(
execution_mode(), &mock_pooled_task_runner_delegate_);
TestWaitableEvent task_ran;
task_runner->PostTask(
FROM_HERE, BindOnce(
[](TestWaitableEvent* task_ran) {
win::AssertComApartmentType(win::ComApartmentType::MTA);
task_ran->Signal();
},
Unretained(&task_ran)));
task_ran.Wait();
}
TEST_P(ThreadGroupTestAllExecutionModes, NoWorkerEnvironment) {
StartThreadGroup(ThreadGroup::WorkerEnvironment::NONE);
auto task_runner = test::CreatePooledTaskRunnerWithExecutionMode(
execution_mode(), &mock_pooled_task_runner_delegate_);
TestWaitableEvent task_ran;
task_runner->PostTask(
FROM_HERE, BindOnce(
[](TestWaitableEvent* task_ran) {
win::AssertComApartmentType(win::ComApartmentType::NONE);
task_ran->Signal();
},
Unretained(&task_ran)));
task_ran.Wait();
}
#endif
TEST_F(ThreadGroupTest, ShouldYieldSingleTask) { … }
TEST_F(ThreadGroupTest, ScheduleJobTaskSource) { … }
TEST_F(ThreadGroupTest, ScheduleJobTaskSourceMultipleTime) { … }
TEST_F(ThreadGroupTest, CancelJobTaskSource) { … }
TEST_F(ThreadGroupTest, JobTaskSourceConcurrencyIncrease) { … }
TEST_F(ThreadGroupTest, ScheduleEmptyJobTaskSource) { … }
TEST_F(ThreadGroupTest, JoinJobTaskSource) { … }
TEST_F(ThreadGroupTest, JoinJobTaskSourceStaleConcurrency) { … }
TEST_F(ThreadGroupTest, CancelJobTaskSourceWithStaleConcurrency) { … }
TEST_F(ThreadGroupTest, JobTaskSourceUpdatePriority) { … }
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
}
}