Commit 152b1041 authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

Expose ScopedTaskEnvironment::DescribePendingMainThreadTasks()

Used while debugging
https://chromium-review.googlesource.com/c/chromium/src/+/1635473
and I think it'll be a nice general purpose debugging tool for
developers.

R=alexclarke@chromium.org

Bug: 946657
Change-Id: I479eb51d00b835bf8a4a75a1b044ab5db12aae13
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1639389Reviewed-by: default avatarAlex Clarke <alexclarke@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Auto-Submit: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665879}
parent e0949be5
......@@ -645,6 +645,10 @@ bool ScopedTaskEnvironment::NextTaskIsDelayed() const {
return !delay.is_zero() && !delay.is_max();
}
void ScopedTaskEnvironment::DescribePendingMainThreadTasks() const {
LOG(INFO) << sequence_manager_->DescribeAllPendingTasks();
}
ScopedTaskEnvironment::TestTaskTracker::TestTaskTracker()
: internal::ThreadPoolImpl::TaskTrackerImpl("ScopedTaskEnvironment"),
can_run_tasks_cv_(&lock_),
......
......@@ -227,9 +227,10 @@ class ScopedTaskEnvironment {
// Returns the current virtual tick time (initially starting at 0).
base::TimeTicks NowTicks() const;
// Only valid for instances with a MOCK_TIME MainThreadType.
// Returns the number of pending tasks (delayed and non-delayed) of the main
// thread's TaskRunner.
// Only valid for instances with a MOCK_TIME MainThreadType. Returns the
// number of pending tasks (delayed and non-delayed) of the main thread's
// TaskRunner. When debugging, you can use DescribePendingMainThreadTasks() to
// see what those are.
size_t GetPendingMainThreadTaskCount() const;
// Only valid for instances with a MOCK_TIME MainThreadType.
......@@ -242,6 +243,10 @@ class ScopedTaskEnvironment {
// is immediate or if there is no next task.
bool NextTaskIsDelayed() const;
// For debugging purposes: Dumps information about pending tasks on the main
// thread.
void DescribePendingMainThreadTasks() const;
protected:
explicit ScopedTaskEnvironment(ScopedTaskEnvironment&& other);
......
......@@ -18,6 +18,7 @@
#include "base/task/thread_pool/thread_pool.h"
#include "base/test/bind_test_util.h"
#include "base/test/mock_callback.h"
#include "base/test/mock_log.h"
#include "base/test/test_timeouts.h"
#include "base/threading/platform_thread.h"
#include "base/threading/sequence_local_storage_slot.h"
......@@ -43,7 +44,11 @@ namespace test {
namespace {
using ::testing::_;
using ::testing::HasSubstr;
using ::testing::IsNull;
using ::testing::Not;
using ::testing::Return;
class ScopedTaskEnvironmentForTest : public ScopedTaskEnvironment {
public:
......@@ -572,6 +577,29 @@ TEST_F(ScopedTaskEnvironmentTest, SetsDefaultRunTimeout) {
EXPECT_EQ(RunLoop::ScopedRunTimeoutForTest::Current(), old_run_timeout);
}
namespace {}
TEST_F(ScopedTaskEnvironmentTest, DescribePendingMainThreadTasks) {
ScopedTaskEnvironment scoped_task_environment;
ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, DoNothing());
test::MockLog mock_log;
mock_log.StartCapturingLogs();
EXPECT_CALL(mock_log, Log(::logging::LOG_INFO, _, _, _,
HasSubstr("scoped_task_environment_unittest.cc")))
.WillOnce(Return(true));
scoped_task_environment.DescribePendingMainThreadTasks();
scoped_task_environment.RunUntilIdle();
EXPECT_CALL(mock_log,
Log(::logging::LOG_INFO, _, _, _,
Not(HasSubstr("scoped_task_environment_unittest.cc"))))
.WillOnce(Return(true));
scoped_task_environment.DescribePendingMainThreadTasks();
}
INSTANTIATE_TEST_SUITE_P(
MainThreadDefault,
ScopedTaskEnvironmentTest,
......
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