chromium/base/threading/scoped_blocking_call_unittest.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

#include "base/threading/scoped_blocking_call.h"

#include <memory>
#include <optional>
#include <utility>
#include <vector>

#include "base/barrier_closure.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/task/thread_pool.h"
#include "base/task/thread_pool/environment_config.h"
#include "base/task/thread_pool/thread_pool_impl.h"
#include "base/test/bind.h"
#include "base/test/gtest_util.h"
#include "base/test/task_environment.h"
#include "base/test/test_waitable_event.h"
#include "base/threading/scoped_blocking_call_internal.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time_override.h"
#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

ElementsAre;

namespace base {

namespace {

class MockBlockingObserver : public internal::BlockingObserver {};

class ScopedBlockingCallTest : public testing::Test {};

}  // namespace

TEST_F(ScopedBlockingCallTest, MayBlock) {}

TEST_F(ScopedBlockingCallTest, WillBlock) {}

TEST_F(ScopedBlockingCallTest, MayBlockWillBlock) {}

TEST_F(ScopedBlockingCallTest, WillBlockMayBlock) {}

TEST_F(ScopedBlockingCallTest, MayBlockMayBlock) {}

TEST_F(ScopedBlockingCallTest, WillBlockWillBlock) {}

TEST_F(ScopedBlockingCallTest, MayBlockWillBlockTwice) {}

TEST(ScopedBlockingCallDestructionOrderTest, InvalidDestructionOrder) {}

namespace {

class ScopedBlockingCallIOJankMonitoringTest : public testing::Test {};

}  // namespace

TEST_F(ScopedBlockingCallIOJankMonitoringTest, Basic) {}

TEST_F(ScopedBlockingCallIOJankMonitoringTest, NestedDoesntMatter) {}

TEST_F(ScopedBlockingCallIOJankMonitoringTest, ManyInAWindow) {}

TEST_F(ScopedBlockingCallIOJankMonitoringTest, OverlappingMultipleWindows) {}

TEST_F(ScopedBlockingCallIOJankMonitoringTest, InstantUnblockReportsZero) {}

// Start the jank mid-interval; that interval should be counted but the last
// incomplete interval won't count.
TEST_F(ScopedBlockingCallIOJankMonitoringTest, Jank7sMidInterval) {}

// Start the jank mid-interval; that interval should be counted but the second
// one won't count.
TEST_F(ScopedBlockingCallIOJankMonitoringTest, Jank1sMidInterval) {}

// Jank that lasts for 1.3 intervals should be rounded down to 1.
TEST_F(ScopedBlockingCallIOJankMonitoringTest, JankRoundDown) {}

// Jank that lasts for 1.7 intervals should be rounded up to 2.
TEST_F(ScopedBlockingCallIOJankMonitoringTest, JankRoundUp) {}

// Start mid-interval and perform an operation that overlaps into the next one
// but is under the jank timing.
TEST_F(ScopedBlockingCallIOJankMonitoringTest, NoJankMidInterval) {}

TEST_F(ScopedBlockingCallIOJankMonitoringTest, MultiThreaded) {}

// 3 janks of 3 seconds; overlapping but starting 1 second apart from each
// other.
TEST_F(ScopedBlockingCallIOJankMonitoringTest, MultiThreadedOverlapped) {}

// 3 janks of 180 seconds; overlapping but starting 60s apart from each other.
// First one starting at 10 seconds (can't start later than that or we'll trip
// the kTimeDiscrepancyTimeout per TaskEnvironment's inability to RunUntilIdle()
// with pending blocked tasks).
TEST_F(ScopedBlockingCallIOJankMonitoringTest, MultiThreadedOverlappedWindows) {}

TEST_F(ScopedBlockingCallIOJankMonitoringTest, CancellationAcrossSleep) {}

TEST_F(ScopedBlockingCallIOJankMonitoringTest, SleepWithLongJank) {}

// Verifies that blocking calls on background workers aren't monitored.
// Platforms where !CanUseBackgroundThreadTypeForWorkerThread() will still
// monitor this jank (as it may interfere with other foreground work).
TEST_F(ScopedBlockingCallIOJankMonitoringTest, BackgroundBlockingCallsIgnored) {}

TEST_F(ScopedBlockingCallIOJankMonitoringTest,
       BackgroundAndForegroundCallsMixed) {}

TEST_F(ScopedBlockingCallIOJankMonitoringTest, WillBlockNotMonitored) {}

TEST_F(ScopedBlockingCallIOJankMonitoringTest,
       NestedWillBlockCancelsMonitoring) {}

TEST_F(ScopedBlockingCallIOJankMonitoringTest, NestedMayBlockIgnored) {}

TEST_F(ScopedBlockingCallIOJankMonitoringTest, BaseSyncPrimitivesNotMonitored) {}

TEST_F(ScopedBlockingCallIOJankMonitoringTest,
       NestedBaseSyncPrimitivesCancels) {}

// Regression test for crbug.com/1209622
TEST_F(ScopedBlockingCallIOJankMonitoringTest,
       RacySampleNearMonitoringWindowBoundary) {}

}  // namespace base