bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2016-2018 Dovecot authors, see the included COPYING file */
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainenstatic unsigned int test_log_throttle_new_events_count;
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainenstatic void test_log_throttle_callback(unsigned int new_events_count,
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen test_log_throttle_new_events_count = new_events_count;
2f4f603d4cebab2cc956c72164efb02da83515c5Timo Sirainen unsigned int i;
d5e839aea288aceaddae28a1578cebda3c9e3b58Timo Sirainen throttle = log_throttle_init(&set, test_log_throttle_callback, ioloop);
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen /* throttle once and drop out just below */
378e6cb162b355d6f103526505bc00b9a78962e7Timo Sirainen for (i = 0; i < 10; i++)
378e6cb162b355d6f103526505bc00b9a78962e7Timo Sirainen test_assert_idx(log_throttle_accept(throttle), i);
25ec868bd8b5375e1c1c4c3331d761667ddfe26cTimo Sirainen for (i = 0; i < 4; i++)
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen test_assert_idx(!log_throttle_accept(throttle), i);
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen test_assert(test_log_throttle_new_events_count == 4);
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen /* throttle and continue just above */
7b032348d7bbb93ff96188289d3dfc1899b9abb3Josef 'Jeff' Sipek for (i = 0; i < 10; i++)
6307d76096764e66bddc63d4a3e5a1aa19cc528fJosef 'Jeff' Sipek test_assert_idx(log_throttle_accept(throttle), i);
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen for (i = 0; i < 5; i++)
2f4f603d4cebab2cc956c72164efb02da83515c5Timo Sirainen test_assert_idx(!log_throttle_accept(throttle), i);
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen test_assert(test_log_throttle_new_events_count == 5);
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen /* we should be still throttled */