7
7
#include " context_builder.hpp"
8
8
#include " events/client_events.hpp"
9
9
#include " events/detail/asio_event_processor.hpp"
10
- #include " events/detail/summarizer.hpp"
11
- #include " serialization/events/json_events.hpp"
12
10
13
11
using namespace launchdarkly ::events::detail;
14
12
@@ -20,101 +18,6 @@ static std::chrono::system_clock::time_point Time1000() {
20
18
return std::chrono::system_clock::from_time_t (1 );
21
19
}
22
20
23
- TEST (SummarizerTests, IsEmptyOnConstruction) {
24
- Summarizer summarizer;
25
- ASSERT_TRUE (summarizer.Empty ());
26
- }
27
-
28
- TEST (SummarizerTests, DefaultConstructionUsesZeroStartTime) {
29
- Summarizer summarizer;
30
- ASSERT_EQ (summarizer.start_time (), TimeZero ());
31
- }
32
-
33
- TEST (SummarizerTests, ExplicitStartTimeIsCorrect) {
34
- auto start = std::chrono::system_clock::now ();
35
- Summarizer summarizer (start);
36
- ASSERT_EQ (summarizer.start_time (), start);
37
- }
38
-
39
- TEST (SummarizerTests, SummaryCounterUpdates) {
40
- using namespace launchdarkly ::events::client;
41
- using namespace launchdarkly ;
42
- Summarizer summarizer;
43
-
44
- auto const feature_key = " cat-food-amount" ;
45
- auto const feature_version = 1 ;
46
- auto const context = ContextBuilder ().kind (" cat" , " shadow" ).build ();
47
- auto const feature_value = Value (3 );
48
- auto const feature_default = Value (1 );
49
- auto const feature_variation = 0 ;
50
-
51
- auto const event = FeatureEventParams{
52
- TimeZero (),
53
- feature_key,
54
- context,
55
- EvaluationResult (
56
- feature_version, std::nullopt, false , false , std::nullopt,
57
- EvaluationDetailInternal (
58
- feature_value, feature_variation,
59
- EvaluationReason (" FALLTHROUGH" , std::nullopt, std::nullopt,
60
- std::nullopt, std::nullopt, false ,
61
- std::nullopt))),
62
- feature_default,
63
- };
64
-
65
- auto const num_events = 10 ;
66
- for (size_t i = 0 ; i < num_events; i++) {
67
- summarizer.Update (event);
68
- }
69
-
70
- auto const & features = summarizer.features ();
71
- auto const & cat_food = features.find (feature_key);
72
- ASSERT_TRUE (cat_food != features.end ());
73
-
74
- auto const & counter = cat_food->second .counters .find (
75
- Summarizer::VariationKey (feature_version, feature_variation));
76
- ASSERT_TRUE (counter != cat_food->second .counters .end ());
77
-
78
- ASSERT_EQ (counter->second .value ().as_double (), feature_value.as_double ());
79
- ASSERT_EQ (counter->second .count (), num_events);
80
- }
81
-
82
- TEST (SummarizerTests, JsonSerialization) {
83
- using namespace launchdarkly ::events::client;
84
- using namespace launchdarkly ;
85
- Summarizer summarizer;
86
-
87
- auto const feature_key = " cat-food-amount" ;
88
- auto const feature_version = 1 ;
89
- auto const context = ContextBuilder ().kind (" cat" , " shadow" ).build ();
90
- auto const feature_value = Value (3 );
91
- auto const feature_default = Value (1 );
92
- auto const feature_variation = 0 ;
93
-
94
- auto const event = FeatureEventParams{
95
- TimeZero (),
96
- feature_key,
97
- context,
98
- EvaluationResult (
99
- feature_version, std::nullopt, false , false , std::nullopt,
100
- EvaluationDetailInternal (
101
- feature_value, feature_variation,
102
- EvaluationReason (" FALLTHROUGH" , std::nullopt, std::nullopt,
103
- std::nullopt, std::nullopt, false ,
104
- std::nullopt))),
105
- feature_default,
106
- };
107
-
108
- auto const num_events = 10 ;
109
- for (size_t i = 0 ; i < num_events; i++) {
110
- summarizer.Update (event);
111
- }
112
- auto json = boost::json::value_from (summarizer.Finish (Time1000 ()));
113
- auto expected = boost::json::parse (
114
- R"( {"kind":"summary","startDate":0,"endDate":1000,"features":{"cat-food-amount":{"default":1E0,"contextKinds":["cat"],"counters":[{"version":1,"variation":0,"value":3E0,"count":10}]}}})" );
115
- ASSERT_EQ (json, expected);
116
- }
117
-
118
21
// This test is a temporary test that exists only to ensure the event processor
119
22
// compiles; it should be replaced by more robust tests (and contract tests.)
120
23
TEST (EventProcessorTests, ProcessorCompiles) {
0 commit comments