userver
C++ Async Framework
Loading...
Searching...
No Matches
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
14
USERVER_NAMESPACE_BEGIN
15
16
namespace
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.
23
class
TestpointClientBase
{
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, Callback callback)
const
= 0;
34
35
protected
:
36
/// Must be called in destructors of derived classes
37
void
Unregister
()
noexcept
;
38
};
39
40
/// @brief Testpoint control interface for testsuite
41
///
42
/// All methods are coro-safe.
43
/// All testpoints are disabled by default.
44
/// Only 1 TestpointControl instance may exist globally at a time.
45
class
TestpointControl
final
{
46
public
:
47
TestpointControl();
48
~TestpointControl();
49
50
/// @brief Enable only the selected testpoints
51
void
SetEnabledNames
(std::unordered_set<std::string> names);
52
53
/// @brief Enable all defined testpoints
54
///
55
/// Testpoints, for which there is no registered handler on the testsuite
56
/// side, will still be skipped, at the cost of an extra request.
57
void
SetAllEnabled
();
58
59
/// @brief Makes a testpoint client globally accessible from testpoints. It
60
/// will unregister itself on destruction.
61
/// @note Only 1 client may be registered at a time.
62
void
SetClient
(
TestpointClientBase
& client);
63
};
64
65
}
// namespace testsuite
66
67
USERVER_NAMESPACE_END
userver
testsuite
testpoint_control.hpp
Generated on Wed Dec 4 2024 18:42:23 for userver by
Doxygen
1.10.0