Skip to content

fix(testing): add retry logic for testing token fetch on 429/5xx#8138

Open
jacekradko wants to merge 1 commit intomainfrom
jacek/retry-testing-token
Open

fix(testing): add retry logic for testing token fetch on 429/5xx#8138
jacekradko wants to merge 1 commit intomainfrom
jacek/retry-testing-token

Conversation

@jacekradko
Copy link
Member

@jacekradko jacekradko commented Mar 20, 2026

Summary

  • Add retry with exponential backoff to the testing token fetch in @clerk/testing
  • The fetchEnvVars function calls testingTokens.createTestingToken() without retry handling, causing E2E test failures when FAPI returns 429 (Too Many Requests)
  • Retries up to 5 times on 429, 502, 503, 504 with exponential backoff + jitter, matching the existing retryableClerkClient used in integration tests

Test plan

  • Verify @clerk/testing builds successfully
  • Run E2E tests with concurrent workers to confirm 429s are retried instead of failing immediately

Summary by CodeRabbit

Tests

  • Added automatic retry logic for testing token operations when encountering rate limits or transient server errors, with exponential backoff.

@changeset-bot
Copy link

changeset-bot bot commented Mar 20, 2026

⚠️ No Changeset found

Latest commit: 65b0620

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Mar 20, 2026 2:17pm

Request Review

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 20, 2026

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@8138

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@8138

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@8138

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@8138

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@8138

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@8138

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@8138

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@8138

@clerk/express

npm i https://pkg.pr.new/@clerk/express@8138

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@8138

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@8138

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@8138

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@8138

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@8138

@clerk/react

npm i https://pkg.pr.new/@clerk/react@8138

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@8138

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@8138

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@8138

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@8138

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@8138

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@8138

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@8138

commit: 65b0620

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: cc2010cb-3a86-44f2-a816-efbad2665e35

📥 Commits

Reviewing files that changed from the base of the PR and between e722e7d and 65b0620.

📒 Files selected for processing (1)
  • packages/testing/src/common/setup.ts

📝 Walkthrough

Walkthrough

The change introduces a new internal helper function fetchWithRetry in the testing setup module that adds retry logic for async operations. This function retries failed calls up to a maximum number of attempts when the error is a Clerk API response error with status codes 429, 502, 503, or 504. Retry delays are calculated from the error's retryAfter property when available, otherwise using exponential backoff with jitter. The retry attempts are logged via console.warn. The testing token fetch operation was updated to use this helper while maintaining existing error handling that logs failures and rethrows errors.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately summarizes the main change: adding retry logic for testing token fetch on specific HTTP error codes (429, 5xx). It clearly identifies both what was changed (testing token fetch) and why (retry logic for 429/5xx errors).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant