diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-05-24 11:40:17 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-05-24 12:42:11 +0000 |
commit | 5d87695f37678f96492b258bbab36486c59866b4 (patch) | |
tree | be9783bbaf04fb930c4d74ca9c00b5e7954c8bc6 /chromium/base/task/thread_pool/service_thread_unittest.cc | |
parent | 6c11fb357ec39bf087b8b632e2b1e375aef1b38b (diff) |
BASELINE: Update Chromium to 75.0.3770.56
Change-Id: I86d2007fd27a45d5797eee06f4c9369b8b50ac4f
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/base/task/thread_pool/service_thread_unittest.cc')
-rw-r--r-- | chromium/base/task/thread_pool/service_thread_unittest.cc | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/chromium/base/task/thread_pool/service_thread_unittest.cc b/chromium/base/task/thread_pool/service_thread_unittest.cc new file mode 100644 index 00000000000..be5a09d2d1c --- /dev/null +++ b/chromium/base/task/thread_pool/service_thread_unittest.cc @@ -0,0 +1,102 @@ +// Copyright 2018 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/task/thread_pool/service_thread.h" + +#include <string> + +#include "base/bind.h" +#include "base/debug/stack_trace.h" +#include "base/task/thread_pool/thread_pool.h" +#include "base/task/thread_pool/thread_pool_impl.h" +#include "base/test/metrics/histogram_tester.h" +#include "base/threading/platform_thread.h" +#include "base/time/time.h" +#include "build/build_config.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace base { +namespace internal { + +namespace { + +// Verifies that |query| is found on the current stack. Ignores failures if this +// configuration doesn't have symbols. +void VerifyHasStringOnStack(const std::string& query) { + const std::string stack = debug::StackTrace().ToString(); + SCOPED_TRACE(stack); + const bool found_on_stack = stack.find(query) != std::string::npos; + const bool stack_has_symbols = + stack.find("SchedulerWorker") != std::string::npos; + EXPECT_TRUE(found_on_stack || !stack_has_symbols) << query; +} + +} // namespace + +#if defined(OS_POSIX) +// Many POSIX bots flakily crash on |debug::StackTrace().ToString()|, +// https://crbug.com/840429. +#define MAYBE_StackHasIdentifyingFrame DISABLED_StackHasIdentifyingFrame +#else +#define MAYBE_StackHasIdentifyingFrame StackHasIdentifyingFrame +#endif + +TEST(ThreadPoolServiceThreadTest, MAYBE_StackHasIdentifyingFrame) { + ServiceThread service_thread(nullptr, DoNothing()); + service_thread.Start(); + + service_thread.task_runner()->PostTask( + FROM_HERE, BindOnce(&VerifyHasStringOnStack, "ServiceThread")); + + service_thread.FlushForTesting(); +} + +// Integration test verifying that a service thread running in a fully +// integrated ThreadPool environment results in reporting +// HeartbeatLatencyMicroseconds metrics. +TEST(ThreadPoolServiceThreadIntegrationTest, HeartbeatLatencyReport) { + ServiceThread::SetHeartbeatIntervalForTesting(TimeDelta::FromMilliseconds(1)); + + ThreadPool::SetInstance(std::make_unique<internal::ThreadPoolImpl>("Test")); + ThreadPool::GetInstance()->StartWithDefaultParams(); + + static constexpr const char* kExpectedMetrics[] = { + "ThreadPool.HeartbeatLatencyMicroseconds.Test." + "UserBlockingTaskPriority", + "ThreadPool.HeartbeatLatencyMicroseconds.Test." + "UserBlockingTaskPriority_MayBlock", + "ThreadPool.HeartbeatLatencyMicroseconds.Test." + "UserVisibleTaskPriority", + "ThreadPool.HeartbeatLatencyMicroseconds.Test." + "UserVisibleTaskPriority_MayBlock", + "ThreadPool.HeartbeatLatencyMicroseconds.Test." + "BackgroundTaskPriority", + "ThreadPool.HeartbeatLatencyMicroseconds.Test." + "BackgroundTaskPriority_MayBlock"}; + + // Each report hits a single histogram above (randomly selected). But 1000 + // reports should touch all histograms at least once the vast majority of the + // time. + constexpr TimeDelta kReasonableTimeout = TimeDelta::FromSeconds(1); + constexpr TimeDelta kBusyWaitTime = TimeDelta::FromMilliseconds(100); + + const TimeTicks start_time = TimeTicks::Now(); + + HistogramTester tester; + for (const char* expected_metric : kExpectedMetrics) { + while (tester.GetAllSamples(expected_metric).empty()) { + if (TimeTicks::Now() - start_time > kReasonableTimeout) + LOG(WARNING) << "Waiting a while for " << expected_metric; + PlatformThread::Sleep(kBusyWaitTime); + } + } + + ThreadPool::GetInstance()->JoinForTesting(); + ThreadPool::SetInstance(nullptr); + + ServiceThread::SetHeartbeatIntervalForTesting(TimeDelta()); +} + +} // namespace internal +} // namespace base |