@@ -47,29 +47,31 @@ class rate_limiter : public dds::rate_limiter {
47
47
TEST (RateLimitTest, OnlyAllowedMaxPerSecond)
48
48
{
49
49
auto timer = std::make_unique<mock::timer>();
50
- ;
51
50
// Four calls within the same second
52
51
timer->responses .push (system_clock::duration (1708963615 ));
53
- timer->responses .push (system_clock::duration (1708963615 ));
54
- timer->responses .push (system_clock::duration (1708963615 ));
55
- timer->responses .push (system_clock::duration (1708963615 ));
56
- // Four extra calls on next second
57
- timer->responses .push (system_clock::duration (1709963630 ));
58
- timer->responses .push (system_clock::duration (1709963630 ));
59
- timer->responses .push (system_clock::duration (1709963630 ));
60
- timer->responses .push (system_clock::duration (1709963630 ));
61
52
62
53
mock::rate_limiter rate_limiter (2 );
63
54
rate_limiter.set_timer (std::move (timer));
64
55
65
- EXPECT_TRUE (rate_limiter.allow ());
66
- EXPECT_TRUE (rate_limiter.allow ());
67
- EXPECT_FALSE (rate_limiter.allow ());
68
- EXPECT_FALSE (rate_limiter.allow ());
69
- EXPECT_TRUE (rate_limiter.allow ());
70
- EXPECT_TRUE (rate_limiter.allow ());
71
- EXPECT_FALSE (rate_limiter.allow ());
72
- EXPECT_FALSE (rate_limiter.allow ());
56
+ int allowed = 0 ;
57
+ for (int i = 0 ; i < 100 ; i++) {
58
+ if (rate_limiter.allow ()) {
59
+ allowed++;
60
+ }
61
+ }
62
+ EXPECT_EQ (2 , allowed);
63
+
64
+ timer = std::make_unique<mock::timer>();
65
+ timer->responses .push (system_clock::duration (1709963630 ));
66
+ rate_limiter.set_timer (std::move (timer));
67
+
68
+ allowed = 0 ;
69
+ for (int i = 0 ; i < 100 ; i++) {
70
+ if (rate_limiter.allow ()) {
71
+ allowed++;
72
+ }
73
+ }
74
+ EXPECT_EQ (2 , allowed);
73
75
}
74
76
75
77
TEST (RateLimitTest, WhenNotMaxPerSecondItAlwaysAllow)
0 commit comments