runtime
478 / 500
question 478 Observability & Operations · hard

Test the retry helper

retry_call(func, attempts, sleep) is shared by every service, so its contract must be pinned by tests: it returns func()'s result; it retries only TimeoutError, calling sleep(2**n) between tries (1, 2, 4 …); it re-raises the last TimeoutError after attempts tries; any other exception is raised immediately without sleeping. Write tests (unittest or test_ functions) that pass for a correct helper and fail for broken ones. Fake func and sleep with small functions or unittest.mock.Mock; nothing should really sleep. Leave the calls to Check.

Targetretry_call(func, attempts, sleep)
Your teststest functions or a TestCase in your file; the starter's helper is correct
Gradedpass for a correct helper, fail for each of three broken helpers

Loading your progress…

Test the retry helper — Python practice · Runtime