forked from ydb-platform/nbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfault_injection_ut.cpp
94 lines (74 loc) · 2.73 KB
/
fault_injection_ut.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "fault_injection.h"
#include <cloud/storage/core/libs/common/error.h>
#include <library/cpp/lwtrace/all.h>
#include <library/cpp/protobuf/util/pb_io.h>
#include <library/cpp/testing/unittest/registar.h>
#define UT_FAULT_INJECTION_PROVIDER(PROBE, EVENT, GROUPS, TYPES, NAMES) \
PROBE(UtFaultInjection, \
GROUPS(), \
TYPES(ui64), \
NAMES("cookie")) \
// UT_FAULT_INJECTION_PROVIDER
LWTRACE_DECLARE_PROVIDER(UT_FAULT_INJECTION_PROVIDER);
LWTRACE_DEFINE_PROVIDER(UT_FAULT_INJECTION_PROVIDER);
namespace NCloud::NBlockStore {
namespace {
////////////////////////////////////////////////////////////////////////////////
std::unique_ptr<NLWTrace::TManager> CreateTraceManager()
{
auto traceManager = std::make_unique<NLWTrace::TManager>(
*Singleton<NLWTrace::TProbeRegistry>(),
true); // allowDestructiveActions
traceManager->RegisterCustomAction(
"ServiceErrorAction",
&CreateServiceErrorActionExecutor);
return traceManager;
}
NLWTrace::TQuery QueryFromString(const TString& text)
{
TStringInput in(text);
NLWTrace::TQuery query;
ParseFromTextFormat(in, query);
return query;
}
void TestFunc(int cookie)
{
GLOBAL_LWPROBE(UT_FAULT_INJECTION_PROVIDER, UtFaultInjection, cookie);
}
} // namespace
////////////////////////////////////////////////////////////////////////////////
Y_UNIT_TEST_SUITE(TFaultInjectionTest)
{
Y_UNIT_TEST(TestServiceErrorAction)
{
auto traceManager = CreateTraceManager();
traceManager->New("env", QueryFromString(R"(
Blocks {
ProbeDesc {
Name: "UtFaultInjection"
Provider: "UT_FAULT_INJECTION_PROVIDER"
}
Action {
CustomAction {
Name: "ServiceErrorAction"
Opts: "E_REJECTED"
Opts: "Error!"
}
}
Predicate {
Operators {
Type: OT_EQ
Argument { Param: "cookie" }
Argument { Value: "42" }
}
}
}
)"));
UNIT_CHECK_GENERATED_NO_EXCEPTION(TestFunc(1), TServiceError);
UNIT_ASSERT_EXCEPTION_SATISFIES(TestFunc(42), TServiceError, [] (auto& e) {
return e.GetCode() == E_REJECTED
&& e.GetMessage().Contains("Error!");
});
}
}
} // namespace NCloud::NBlockStore