Skip to content

chore(warehouse-sources): stop slowest CI tests wasting runner time - #70291

Merged
pauldambra merged 1 commit into
masterfrom
posthog-code/fix-slow-ci-tests
Jul 12, 2026
Merged

chore(warehouse-sources): stop slowest CI tests wasting runner time#70291
pauldambra merged 1 commit into
masterfrom
posthog-code/fix-slow-ci-tests

Conversation

@pauldambra

Copy link
Copy Markdown
Member

Problem

Trunk's slowest-tests report shows the statuspage retry tests dominating CI runner time. TestFetchPage.test_retryable_statuses_raise mocks session.get but leaves tenacity's @retry backoff un-mocked, so each of the 5 parametrized status codes does 7 real exponential-backoff sleeps (2+4+8+16+32+60+60 ≈ 3 minutes of wall clock) on every CI run. It's the single largest source of wasted runner time in the suite.

The same report flags test_migration_0014.py. Its TestMigrations base replays migrations backward and forward in setUp for each of the class's 10 expanded test IDs, and the migration under test is an elidable one-off backfill with dozens of migrations shipped on top of it. It's long applied everywhere and has nothing left to guard.

Changes

  • Patch tenacity.nap.time.sleep via monkeypatch in test_retryable_statuses_raise, so retries run instantly. The production retry config is untouched and the test still exercises the full retry count (now asserted via session.get.call_count == 8) and the reraise behavior. All 5 cases drop from ~3 minutes each to milliseconds.
  • Delete products/warehouse_sources/backend/tests/test_migration_0014.py.

How did you test this code?

Ran pytest products/.../statuspage/tests/test_statuspage.py::TestFetchPage locally: 7 passed in ~9s (previously the retry cases alone took ~15 minutes). The new call_count assertion catches a regression no prior test did: someone reducing _MAX_ATTEMPTS or breaking the retry predicate would previously still pass, since the test only checked that the exception surfaced eventually. No coverage replaces the deleted migration test, deliberately, since the backfill has shipped everywhere.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Docs update

No docs affected.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Claude (PostHog Code) authored this from a slowest-tests report review. Sonnet subagents investigated each slow test; these two were the cheap, high-confidence fixes (the funnel time-to-convert compare test and the stateright model tests need separate, more involved changes). Skills invoked: /writing-tests. Considered making the retry backoff configurable in production code instead, rejected as test-only plumbing in a production signature; the monkeypatch is self-contained and auto-restored.


Created with PostHog Code

Two changes targeting the top of the slowest-tests report:

- test_retryable_statuses_raise did real tenacity exponential-backoff
  sleeps (~3 min per parametrized case, 5 cases, every CI run). Patch
  tenacity's sleep so retries run instantly while still exercising the
  full retry count and reraise behavior.
- Delete test_migration_0014.py: the 0014 backfill is an elidable
  one-off data migration with dozens of migrations shipped on top of
  it, and the TestMigrations base replays migrations in setUp for each
  of the 10 expanded test IDs.

Generated-By: PostHog Code
Task-Id: 55a3d6ea-3391-4b9e-91fb-a2da870c2b05
@github-actions

Copy link
Copy Markdown
Contributor

Hey @pauldambra! 👋

It looks like your git author email on this PR isn't your @posthog.com address (paul.dambra@gmail.com). Since you're on the PostHog team, it's worth pointing your local git author email at your @posthog.com address. Why it matters:

  • Consistent work identity in git history — internal tooling that attributes commits to team members keys off your @posthog.com address.
  • Keeps team contributions easy to tell apart from external community ones when scanning history.

You can fix it for this repo with:

git config user.email "you@posthog.com"

Or set it globally with git config --global user.email "you@posthog.com". No need to redo this PR — just a nudge for next time. 🙂

@pauldambra
pauldambra marked this pull request as ready for review July 12, 2026 13:20
@pr-assigner-resolver-posthog
pr-assigner-resolver-posthog Bot requested a review from a team July 12, 2026 13:21
@pauldambra pauldambra added the stamphog Request AI approval (no full review) label Jul 12, 2026
@pauldambra
pauldambra enabled auto-merge (squash) July 12, 2026 13:21

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Test-only change: mocks tenacity's sleep so a slow retry test runs fast (strengthened with a call_count assertion) and deletes tests for a long-applied, superseded data migration. No production code touched, diff matches description, and two bot reviewers already gave a thumbs up.

  • 👍 on the PR from chatgpt-codex-connector[bot], hex-security-app[bot].
Gate mechanics and policy version
Gate Result
prerequisites all clear
deny-list no deny categories matched
size 0L, 0F substantive, 100L/2F incl. docs/generated/snapshots — within ceiling
tier T0 auto-approve: T0-deterministic (100L, 2F, single-area, chore)
stamphog 2.0.0b3 .stamphog/policy.yml @ 576c226 · reviewed head c64cbfc

@trunk-io

trunk-io Bot commented Jul 12, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@pauldambra
pauldambra merged commit dc71029 into master Jul 12, 2026
311 of 321 checks passed
@pauldambra
pauldambra deleted the posthog-code/fix-slow-ci-tests branch July 12, 2026 13:43
@deployment-status-posthog

deployment-status-posthog Bot commented Jul 12, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-07-12 14:06 UTC Run
prod-us ✅ Deployed 2026-07-12 14:17 UTC Run
prod-eu ✅ Deployed 2026-07-12 14:18 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stamphog Request AI approval (no full review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant