diff options
author | George Kadianakis <desnacked@riseup.net> | 2021-03-10 14:37:36 +0200 |
---|---|---|
committer | George Kadianakis <desnacked@riseup.net> | 2021-03-17 18:22:38 +0200 |
commit | 7740a8b5d4de649e3ba2a0578f789140725974b6 (patch) | |
tree | f6ff31bb373afeb7c3b70fcc12b5b61e7c5635bf /src/test/test_stats.c | |
parent | e688580277cd0223a32bf08603013b59693c713c (diff) | |
download | tor-7740a8b5d4de649e3ba2a0578f789140725974b6.tar.gz tor-7740a8b5d4de649e3ba2a0578f789140725974b6.zip |
Rate-limit counter should increase once per minute.
Diffstat (limited to 'src/test/test_stats.c')
-rw-r--r-- | src/test/test_stats.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/test/test_stats.c b/src/test/test_stats.c index 1f14255e31..a22a42f723 100644 --- a/src/test/test_stats.c +++ b/src/test/test_stats.c @@ -807,6 +807,45 @@ test_overload_stats(void *arg) stats_str = rep_hist_get_overload_stats_lines(); tt_assert(!stats_str); + /* Now test the rate-limit rate-limiter ;) */ + for (int i = 0; i < 10; i++) { + rep_hist_note_overload(OVERLOAD_READ); + } + /* We already have an event registered from the previous tests. We just + * registered ten more overload events, but only one should have been counted + * because of the rate limiter */ + stats_str = rep_hist_get_overload_stats_lines(); + tt_str_op("overload-ratelimits 1 2002-01-10 02:00:00 1000 2000 2 0", + OP_EQ, stats_str); + tor_free(stats_str); + + /* Increment time by 59 secs and try again. No additional events should + register */ + current_time += 59; + update_approx_time(current_time); + + for (int i = 0; i < 10; i++) { + rep_hist_note_overload(OVERLOAD_READ); + } + stats_str = rep_hist_get_overload_stats_lines(); + tt_str_op("overload-ratelimits 1 2002-01-10 02:00:00 1000 2000 2 0", + OP_EQ, stats_str); + tor_free(stats_str); + + /* Now increment time by 2 secs -- taking it after the minute rate limiting + and see that events will register again */ + current_time += 2; + update_approx_time(current_time); + + for (int i = 0; i < 10; i++) { + rep_hist_note_overload(OVERLOAD_READ); + rep_hist_note_overload(OVERLOAD_WRITE); + } + stats_str = rep_hist_get_overload_stats_lines(); + tt_str_op("overload-ratelimits 1 2002-01-10 02:00:00 1000 2000 3 1", + OP_EQ, stats_str); + tor_free(stats_str); + done: tor_free(stats_str); } |