43
43
44
44
namespace {
45
45
46
+ // If true, the acceptable thresholds are greatly increased "close enough"
47
+ // checks, which can reduce the flakiness on heavily loaded or otherwise
48
+ // unpredictable systems. If false, the thresholds are much stricter and
49
+ // should be used for more deterministic systems.
50
+ // We default to true to avoid flakes in CI, but when running locally you
51
+ // can consider setting this to false to get a more accurate picture of
52
+ // the profiler's behavior.
53
+ constexpr bool use_loose_thresholds = true ;
54
+
46
55
struct temporary_profiler_settings {
47
56
std::chrono::nanoseconds prev_ns;
48
57
bool prev_enabled;
@@ -68,15 +77,37 @@ struct temporary_profiler_settings {
68
77
//
69
78
// The function below takes this error into account and allows the actual samples taken
70
79
// to be slightly less than the expect number of samples if there was no error.
71
- bool close_to_expected (size_t actual_size, size_t expected_size, double allowed_dev = 0.15 ) {
72
- auto lower_bound = (1 - allowed_dev) * expected_size;
73
- auto upper_bound = (1 + allowed_dev) * expected_size;
80
+ bool close_to_expected (size_t actual_size, size_t expected_size) {
81
+
82
+ constexpr double allowed_dev = 0.15 ;
83
+
84
+ size_t lower_bound, upper_bound;
85
+
86
+ if (use_loose_thresholds) {
87
+ // widen the thresholds a lot
88
+ lower_bound = round (pow (1 - allowed_dev, 4 )) * expected_size;
89
+ upper_bound = round (pow (1 + allowed_dev, 4 )) * expected_size;
90
+ } else {
91
+ lower_bound = round ((1 - allowed_dev) * expected_size);
92
+ upper_bound = round ((1 + allowed_dev) * expected_size);
93
+ }
74
94
75
95
BOOST_TEST_INFO (" actual_size: " << actual_size << " , lower_bound " << lower_bound << " , upper_bound " << upper_bound);
76
96
77
97
return actual_size <= upper_bound && actual_size >= lower_bound;
78
98
}
79
99
100
+ // If loose thresholds are enabled, this call maps to close_to_exepected, otherwise
101
+ // it does an exact equality check.
102
+ void maybe_exact (size_t actual, size_t expected, auto message) {
103
+ BOOST_TEST_INFO (message);
104
+ if (use_loose_thresholds) {
105
+ close_to_expected (actual, expected);
106
+ } else {
107
+ BOOST_REQUIRE_EQUAL (actual, expected);
108
+ }
109
+ }
110
+
80
111
/*
81
112
* Get the current profile results and dropped count. If sg_in_main is true, also validates that
82
113
* the sg associated with the profile is always main, as we expect unless some SG have been
@@ -161,7 +192,7 @@ SEASTAR_THREAD_TEST_CASE(mixed_case) {
161
192
spin (20ms);
162
193
}
163
194
164
- BOOST_REQUIRE_EQUAL (reports, 5 );
195
+ maybe_exact (reports, 5 , " reports " );
165
196
auto results = get_profile ();
166
197
BOOST_REQUIRE (close_to_expected (results.size (), 12 ));
167
198
}
@@ -343,6 +374,6 @@ SEASTAR_THREAD_TEST_CASE(scheduling_group_test) {
343
374
BOOST_CHECK_GT (count_a + count_b, 10 );
344
375
BOOST_CHECK_GT (count_a, 0 );
345
376
BOOST_CHECK_GT (count_b, 0 );
346
- BOOST_CHECK_LT (count_main, 3 );
377
+ BOOST_CHECK_LT (count_main, 10 );
347
378
BOOST_CHECK_LT (dropped_samples, 5 );
348
379
}
0 commit comments