Skip to content

Add unit tests for apple and play with_retry - #21

Merged
FidelisMM merged 1 commit into
FidelisMM:mainfrom
CodeByPeace:test/with-retry-19
Oct 2, 2026
Merged

FidelisMM merged 1 commit into
FidelisMM:mainfrom
CodeByPeace:test/with-retry-19

Conversation

@CodeByPeace

Copy link
Copy Markdown
Contributor

Closes #19

What

Adds tests/test_retry.py with unit tests for with_retry in both apple.py and play.py. time.sleep is patched, so the tests run instantly, and a small fake function fails a set number of times before succeeding.

Apple:

  • succeeds after transient failures and returns the value
  • retries httpx.HTTPStatusError
  • gives up after tentativas attempts and raises AppleError with the original error as the cause

Play:

  • succeeds after transient failures
  • re-raises the original httpx.TransportError after the last attempt
  • retries a PlayError containing " HTTP 5", and re-raises it after the last attempt
  • does not retry a 4xx PlayError (one call, no sleep)

Both: the backoff waits 2, 4, 8, 16 seconds with the default 5 attempts.

I also temporarily changed the " HTTP 5" check in play.py and confirmed the new tests fail, then restored it. No source files are changed.

Tested against

  • Real store (which one, test app)
  • Only offline (compile/import)

Ran the three CI checks locally: ruff, the unit tests (22 pass), and the compile check.

Checklist

  • No credentials, real account ids or personal data
  • Not applicable: no publishing tools and no store quirk changed

AI use: I used Claude Sonnet 5.5 to help write the tests. I ran them, checked them by breaking the Play 5xx check, and reviewed the final code myself.

Covers retry-then-succeed, giving up after the attempt limit, the Play 4xx/5xx distinction, and the 2, 4, 8, 16 backoff, with time.sleep patched.

@FidelisMM FidelisMM left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @CodeByPeace, and that was fast! This covers everything #19 asked for, for both stores: transient failures, giving up after tentativas (Apple wrapping in AppleError with the cause kept, Play re-raising the original), 5xx vs 4xx PlayError, and the 2/4/8/16 backoff. The Flaky helper keeps every test readable. I also flipped the " HTTP 5" check locally and the suite caught it, same as you did. 22/22 pass, ruff clean, CI green. Merging now.

@FidelisMM
FidelisMM merged commit f9f6c17 into FidelisMM:main Oct 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unit tests for with_retry in apple.py and play.py

2 participants