"""Calcul du delai de reconnexion automatique (backoff exponentiel plafonne).""" import sys, pathlib sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent.parent)) from app.services.reconnect import compute_backoff_delay print("=== 1. Progression exponentielle ===") delays = [compute_backoff_delay(n, initial_delay=5) for n in range(1, 6)] print(" delais:", delays) assert delays == [5, 10, 20, 40, 60], delays # le 5e (80s) est plafonne a 60s print(" OK") print() print("=== 2. Plafond respecte au-dela ===") assert compute_backoff_delay(10, initial_delay=5, max_delay=60) == 60 assert compute_backoff_delay(20, initial_delay=5, max_delay=120) == 120 print(" OK") print() print("=== 3. Tentative < 1 traitee comme la premiere ===") assert compute_backoff_delay(0, initial_delay=5) == 5 assert compute_backoff_delay(-3, initial_delay=5) == 5 print(" OK") print() print("=== 4. Delai initial personnalise ===") assert compute_backoff_delay(1, initial_delay=10) == 10 assert compute_backoff_delay(2, initial_delay=10) == 20 print(" OK") print() print("BACKOFF DE RECONNEXION : TOUS LES TESTS OK")