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
<
string
>
8
#
include
<
unordered_set
>
9
10
#
include
<
userver
/
formats
/
json_fwd
.
hpp
>
11
12
USERVER_NAMESPACE_BEGIN
13
14
namespace
testsuite
{
15
16
/// @brief Base testpoint client. Used to report TESTPOINT executions to
17
/// testsuite.
18
///
19
/// Do not use directly unless you are writing a component for handling
20
/// testpoints.
21
class
TestpointClientBase
{
22
public
:
23
using
Callback = std::function<
void
(
const
formats::
json
::Value&)>;
24
25
virtual
~TestpointClientBase();
26
27
/// @param name the name of the testpoint
28
/// @param json the request that will be passed to testsuite handler
29
/// @param callback will be invoked with the response if the testpoint has
30
/// been handled on the testsuite side successfully
31
virtual
void
Execute
(
const
std::string& name,
32
const
formats::
json
::Value& json,
33
const
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 Oct 4 2023 12:14:48 for userver by
Doxygen
1.9.8