Skip to content

Commit e2cd1d5

Browse files
committed
Amend tests
1 parent b5236d4 commit e2cd1d5

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

appsec/tests/helper/rate_limit_test.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,31 @@ class rate_limiter : public dds::rate_limiter {
4747
TEST(RateLimitTest, OnlyAllowedMaxPerSecond)
4848
{
4949
auto timer = std::make_unique<mock::timer>();
50-
;
5150
// Four calls within the same second
5251
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));
6152

6253
mock::rate_limiter rate_limiter(2);
6354
rate_limiter.set_timer(std::move(timer));
6455

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);
7375
}
7476

7577
TEST(RateLimitTest, WhenNotMaxPerSecondItAlwaysAllow)

0 commit comments

Comments
 (0)