From: Kyle Fuller Date: Sat, 24 Sep 2022 12:02:54 +0000 (+0100) Subject: fix: switch to less aggressive backoff algorithm X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=42ce5b93f86db9b9c70a58f8e28063e0390168fc;p=znc-palaver.git fix: switch to less aggressive backoff algorithm This results in retry delays of: * 2 seconds * 4 seconds * 6 seconds * 8 seconds * 10 seconds --- diff --git a/palaver.cpp b/palaver.cpp index a548df8..f136bcf 100644 --- a/palaver.cpp +++ b/palaver.cpp @@ -10,7 +10,6 @@ #define ZNC_PALAVER_VERSION "1.2.1" #include -#include #include #include @@ -128,9 +127,9 @@ public: } unsigned int GetDelay(unsigned int uAttempts) { - double minimumBackoff = 1; - double maximumBackoff = 10; - return std::max(std::min(pow((double)uAttempts, 2), maximumBackoff), minimumBackoff); + unsigned int minimumBackoff = 1; + unsigned int maximumBackoff = 10; + return std::max(std::min(uAttempts * 2, maximumBackoff), minimumBackoff); } }; diff --git a/test/test_palaver.py b/test/test_palaver.py index 7266bc7..d6994d1 100644 --- a/test/test_palaver.py +++ b/test/test_palaver.py @@ -320,7 +320,7 @@ async def test_receiving_notification_with_retry_on_rate_limit(znc): line = await reader.readline() assert line == b':*palaver!znc@znc.in PRIVMSG admin :Notification sent to 1 clients.\r\n' - await asyncio.sleep(1.2) + await asyncio.sleep(2.2) server.close() await server.wait_closed() @@ -376,7 +376,7 @@ async def test_receiving_notification_with_retry_on_server_error(znc): line = await reader.readline() assert line == b':*palaver!znc@znc.in PRIVMSG admin :Notification sent to 1 clients.\r\n' - await asyncio.sleep(1.2) + await asyncio.sleep(2.2) server.close() await server.wait_closed() @@ -433,7 +433,7 @@ async def test_receiving_notification_with_retry_on_disconnect(znc): line = await reader.readline() assert line == b':*palaver!znc@znc.in PRIVMSG admin :Notification sent to 1 clients.\r\n' - await asyncio.sleep(1.2) + await asyncio.sleep(2.2) server.close() await server.wait_closed()