runtime
308 / 500
question 308 HTTP & API Clients · medium

Tests for backoff delays

backoff.py has backoff_delays(attempts, base, cap), which a retry loop uses: the waits before each retry are base, 2·base, 4·base, …, one fewer than the number of attempts, and none longer than cap. Write unittest tests that pass on the real function and catch the usual mistakes in it.

Writea unittest.TestCase class (or top-level test_ functions with assert) that calls backoff_delays
Rulesbackoff_delays(4, 1, 30) → [1, 2, 4]; backoff_delays(6, 5, 30) → [5, 10, 20, 30, 30]; one attempt → []
Gradedyour tests run against the real function and against several broken versions; don't call them yourself

Loading your progress…

Tests for backoff delays — Python practice · Runtime