Skip to content

Commit

Permalink
Generate a static epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
estringana committed Feb 28, 2024
1 parent f841015 commit 2036ae4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions appsec/tests/helper/rate_limit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,30 @@ class rate_limiter : public dds::rate_limiter {

TEST(RateLimitTest, OnlyAllowedMaxPerSecond)
{
auto first_round_time = system_clock::now();
auto second_round_time = first_round_time + std::chrono::seconds(5);

std::unique_ptr<mock::timer> timer = std::make_unique<mock::timer>();
// Four calls within the same second
timer->responses.push(system_clock::duration(1708963615));
timer->responses.push(first_round_time.time_since_epoch());

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

int allowed = 0;
for (int i = 0; i < 100; i++) {
for (int i = 0; i < 10; i++) {
if (rate_limiter.allow()) {
allowed++;
}
}
EXPECT_EQ(2, allowed);

timer = std::make_unique<mock::timer>();
timer->responses.push(system_clock::duration(1709963630));
timer->responses.push(second_round_time.time_since_epoch());
rate_limiter.set_timer(std::move(timer));

allowed = 0;
for (int i = 0; i < 100; i++) {
for (int i = 0; i < 10; i++) {
if (rate_limiter.allow()) {
allowed++;
}
Expand Down

0 comments on commit 2036ae4

Please sign in to comment.