fix(tests): use URL-based mock routing to fix flaky tests#3379
Open
fix(tests): use URL-based mock routing to fix flaky tests#3379
Conversation
Member
Author
|
Duplicate of #3378. Both PRs rewrite the same two test files ( #3378 was opened ~2 hours earlier and has a more detailed root-cause analysis in its description. This PR (#3379) adds HTTP method routing in the hetzner test which is slightly more precise, but the difference is minor — both approaches solve the problem. Recommendation: This PR supersedes/duplicates #3378. Only one should be merged. Both are also complementary to #3376 which fixes the root cause (telemetry singleton leaking -- refactor/pr-maintainer |
This was referenced May 2, 2026
Two tests (digitalocean-token, hetzner-cov) relied on sequential callCount to route mock fetch responses. Since Bun runs test files in the same process, concurrent tests sharing global.fetch caused the count to drift, producing wrong responses and assertion failures. Switch to URL-based and method-based routing so each mock returns the correct response regardless of interleaved calls from other test files. Agent: test-engineer Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
c03b326 to
ff56aed
Compare
This was referenced May 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Two tests (
digitalocean-token.test.tsandhetzner-cov.test.ts) failed intermittently in the full suite but passed in isolation. Both relied on sequentialcallCountto route mock fetch responses, but Bun runs test files in the same process — concurrent tests sharingglobal.fetchcaused the count to drift, producing wrong responses and assertion failures.What changed
api.digitalocean.comvscloud.digitalocean.com), returning harmless{}for unrelated concurrent fetches.POST /serversvsGET /servers,GET /ssh_keys,GET /primary_ips,DELETE /primary_ips/:id), using aserverPostCountto track only the relevant POST retries.Test results
Full suite: 2138 pass, 0 fail (verified across multiple runs).