Skip to content

Commit 2036ae4

Browse files
committed
Generate a static epoch
1 parent f841015 commit 2036ae4

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

appsec/tests/helper/rate_limit_test.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,30 @@ class rate_limiter : public dds::rate_limiter {
4747

4848
TEST(RateLimitTest, OnlyAllowedMaxPerSecond)
4949
{
50+
auto first_round_time = system_clock::now();
51+
auto second_round_time = first_round_time + std::chrono::seconds(5);
52+
5053
std::unique_ptr<mock::timer> timer = std::make_unique<mock::timer>();
5154
// Four calls within the same second
52-
timer->responses.push(system_clock::duration(1708963615));
55+
timer->responses.push(first_round_time.time_since_epoch());
5356

5457
mock::rate_limiter rate_limiter(2);
5558
rate_limiter.set_timer(std::move(timer));
5659

5760
int allowed = 0;
58-
for (int i = 0; i < 100; i++) {
61+
for (int i = 0; i < 10; i++) {
5962
if (rate_limiter.allow()) {
6063
allowed++;
6164
}
6265
}
6366
EXPECT_EQ(2, allowed);
6467

6568
timer = std::make_unique<mock::timer>();
66-
timer->responses.push(system_clock::duration(1709963630));
69+
timer->responses.push(second_round_time.time_since_epoch());
6770
rate_limiter.set_timer(std::move(timer));
6871

6972
allowed = 0;
70-
for (int i = 0; i < 100; i++) {
73+
for (int i = 0; i < 10; i++) {
7174
if (rate_limiter.allow()) {
7275
allowed++;
7376
}

0 commit comments

Comments
 (0)