mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-04 08:01:49 +00:00
##### SUMMARY Replace the constant poll interval of 1 second, with a truncated exponential back off algorithm with jitter. Below is a suite of poll interval (in seconds) generated by the new algorithm: ``` 1.49 2.14 5.46 6.51 6.57 5.57 5.98 7.13 6.59 7.10 5.54 5.03 6.56 5.96 6.72 7.21 7.05 5.31 5.60 6.33 6.82 5.42 6.08 6.60 TOTAL: 140.77 ```
14 lines
484 B
Python
14 lines
484 B
Python
from __future__ import annotations
|
|
|
|
from ansible_collections.hetzner.hcloud.plugins.module_utils.client import (
|
|
exponential_backoff_poll_interval,
|
|
)
|
|
|
|
|
|
def test_exponential_backoff_poll_interval():
|
|
poll_interval = exponential_backoff_poll_interval(base=1.0, multiplier=2, cap=5.0, jitter=0.0)
|
|
poll_max_retries = 25
|
|
|
|
results = [poll_interval(i) for i in range(poll_max_retries)]
|
|
assert sum(results) == 117.0
|
|
assert results[:6] == [1.0, 2.0, 4.0, 5.0, 5.0, 5.0]
|