MCPcopy
hub / github.com/urllib3/urllib3 / test_backoff_jitter

Method test_backoff_jitter

test/test_retry.py:196–223  ·  view source on GitHub ↗

Backoff with jitter is computed correctly

(self)

Source from the content-addressed store, hash-verified

194 assert retry.parse_retry_after(str(2)) == 1
195
196 def test_backoff_jitter(self) -> None:
197 """Backoff with jitter is computed correctly"""
198 max_backoff = 1
199 jitter = 0.4
200 retry = Retry(
201 total=100,
202 backoff_factor=0.2,
203 backoff_max=max_backoff,
204 backoff_jitter=jitter,
205 )
206 assert retry.get_backoff_time() == 0 # First request
207
208 retry = retry.increment(method="GET")
209 assert retry.get_backoff_time() == 0 # First retry
210
211 retry = retry.increment(method="GET")
212 assert retry.backoff_factor == 0.2
213 assert retry.total == 98
214 assert 0.4 <= retry.get_backoff_time() <= 0.8 # Start backoff
215
216 retry = retry.increment(method="GET")
217 assert 0.8 <= retry.get_backoff_time() <= max_backoff
218
219 retry = retry.increment(method="GET")
220 assert retry.get_backoff_time() == max_backoff
221
222 retry = retry.increment(method="GET")
223 assert retry.get_backoff_time() == max_backoff
224
225 def test_zero_backoff(self) -> None:
226 retry = Retry()

Callers

nothing calls this directly

Calls 3

get_backoff_timeMethod · 0.95
incrementMethod · 0.95
RetryClass · 0.90

Tested by

no test coverage detected