After a recent PR in a small notification scheduling service, odd behavior appeared: some jobs get the same label, and deferred sending fires for a different time window than the one configured when the job was created. You need to review the changes and identify the defects.
Context and requirements:
scheduler.py:
build_labelers(prefixes: list[str]) -> list[Callable[[str], str]] returns a list of functions. Each function accepts user_id: str and must return a string of the form "<prefix>:<user_id>" for the corresponding element of prefixes.build_reminders(windows: list[int]) -> list[Reminder] returns a list of Reminder objects with the same length as windows.Reminder(delay_seconds: int, send: Callable[[str], Awaitable[str]]) stores reminder parameters.await Reminder.schedule(user_id: str) -> str waits delay_seconds, then calls send(user_id) and returns its result.build_labelers(["email", "sms", "push"]) must produce "email:u1", "sms:u1", "push:u1";Reminder created from build_reminders([5, 30, 90]) must schedule sending with its own delay value;Reproduction steps:
python -m demo.Assumptions:
asyncio.sleep is not mocked.CPython 3.12.2, standard library only. Run: python -m demo from the directory containing scheduler.py and demo.py. Any OS with a standard asyncio event loop is fine.
Use line comments to explain the problem, its impact, the fix and how to test it.