userver
C++ Async Framework
Loading...
Searching...
No Matches
stress.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/utest/stress.hpp
4
/// @brief @copybrief utest::StressLoop
5
6
#
include
<
chrono
>
7
8
#
include
<
userver
/
engine
/
deadline
.
hpp
>
9
10
USERVER_NAMESPACE_BEGIN
11
12
namespace
utest {
13
14
/// @brief Helper for stress tests for watching for
15
/// "OK, we have been running for enough time, let's stop" event.
16
///
17
/// Example:
18
/// @code
19
/// for (auto _: utest::StressLoop()) {
20
/// ...
21
/// }
22
/// @endcode
23
class
StressLoop
{
24
public
:
25
struct
Iterator
{
26
StressLoop
& loop;
27
28
struct
Value
{
29
~Value() {
30
(
void
)0;
// force non-trivial destructor
31
}
32
};
33
34
void
operator++() {}
35
Value
operator*() {
return
{}; }
36
bool
operator==(
const
Iterator
&)
const
{
return
loop.ShouldStop(); }
37
bool
operator!=(
const
Iterator
&)
const
{
return
!loop.ShouldStop(); }
38
};
39
40
Iterator
begin() {
return
{*
this
}; }
41
42
Iterator
end() {
return
{*
this
}; }
43
44
bool
ShouldStop()
const
{
return
deadline_.IsReached(); }
45
46
private
:
47
static
constexpr
std::chrono::seconds kMaxStressTestWaitTime{30};
48
49
engine::Deadline deadline_{engine::Deadline::FromDuration(kMaxStressTestWaitTime)};
50
};
51
52
}
// namespace utest
53
54
USERVER_NAMESPACE_END
userver
utest
stress.hpp
Generated on Tue Dec 30 2025 09:15:51 for userver by
Doxygen
1.9.8