Systemd/src/test/test-ratelimit.c
Zbigniew Jędrzejewski-Szmek 7994ac1d85 Rename ratelimit_test to ratelimit_below
When I see "test", I have to think three times what the return value
means. With "below" this is immediately clear. ratelimit_below(&limit)
sounds almost like English and is imho immediately obvious.

(I also considered ratelimit_ok, but this strongly implies that being under the
limit is somehow better. Most of the times this is true, but then we use the
ratelimit to detect triple-c-a-d, and "ok" doesn't fit so well there.)

C.f. a1bcaa07.
2018-05-13 22:08:30 +02:00

35 lines
791 B
C

/* SPDX-License-Identifier: LGPL-2.1+ */
/***
This file is part of systemd
Copyright 2014 Ronny Chevalier
***/
#include <unistd.h>
#include "macro.h"
#include "ratelimit.h"
#include "time-util.h"
static void test_ratelimit_below(void) {
int i;
RATELIMIT_DEFINE(ratelimit, 1 * USEC_PER_SEC, 10);
for (i = 0; i < 10; i++)
assert_se(ratelimit_below(&ratelimit));
assert_se(!ratelimit_below(&ratelimit));
sleep(1);
for (i = 0; i < 10; i++)
assert_se(ratelimit_below(&ratelimit));
RATELIMIT_INIT(ratelimit, 0, 10);
for (i = 0; i < 10000; i++)
assert_se(ratelimit_below(&ratelimit));
}
int main(int argc, char *argv[]) {
test_ratelimit_below();
return 0;
}