userver: userver/testsuite/testpoint_control.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
testpoint_control.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/testsuite/testpoint_control.hpp
4/// @brief @copybrief testsuite::TestpointControl
5
6#include <functional>
7#include <optional>
8#include <string>
9#include <unordered_set>
10
11#include <userver/formats/json_fwd.hpp>
12#include <userver/utils/function_ref.hpp>
13
14USERVER_NAMESPACE_BEGIN
15
16namespace testsuite {
17
18/// @brief Base testpoint client. Used to report TESTPOINT executions to
19/// testsuite.
20///
21/// Do not use directly unless you are writing a component for handling
22/// testpoints.
24 public:
25 using Callback = utils::function_ref<void(const formats::json::Value&)>;
26
27 virtual ~TestpointClientBase();
28
29 /// @param name the name of the testpoint
30 /// @param json the request that will be passed to testsuite handler
31 /// @param callback will be invoked with the response if the testpoint has
32 /// been handled on the testsuite side successfully
33 virtual void Execute(std::string_view name, const formats::json::Value& json,
34 Callback callback) const = 0;
35
36 protected:
37 /// Must be called in destructors of derived classes
38 void Unregister() noexcept;
39};
40
41/// @brief Testpoint control interface for testsuite
42///
43/// All methods are coro-safe.
44/// All testpoints are disabled by default.
45/// Only 1 TestpointControl instance may exist globally at a time.
46class TestpointControl final {
47 public:
48 TestpointControl();
49 ~TestpointControl();
50
51 /// @brief Enable only the selected testpoints
52 void SetEnabledNames(std::unordered_set<std::string> names);
53
54 /// @brief Enable all defined testpoints
55 ///
56 /// Testpoints, for which there is no registered handler on the testsuite
57 /// side, will still be skipped, at the cost of an extra request.
59
60 /// @brief Makes a testpoint client globally accessible from testpoints. It
61 /// will unregister itself on destruction.
62 /// @note Only 1 client may be registered at a time.
64};
65
66} // namespace testsuite
67
68USERVER_NAMESPACE_END