Skip to content

bug: flaky tests due to global.fetch mock pollution in parallel test execution #3393

@la14-1

Description

@la14-1

Summary

Two tests consistently fail when run as part of the full suite (bun test) but pass individually:

  1. hetzner-cov.test.ts: "cleans up orphaned primary IPs on resource_limit_exceeded and retries"
  2. digitalocean-token.test.ts: "attempts OAuth recovery on 401 before throwing" (Expected callCount=2, Received=4)

Root Cause

Bun runs test files in the same process. global.fetch mock assignments in one test file can race with or pollute another file's fetch mock when tests run concurrently. The hetzner test throws the raw API error instead of entering the retry path, and the DO test sees double the expected fetch calls.

Both tests pass in isolation and in small groups. CI may not reproduce this if the test runner scheduling differs.

Suggested Fix

  • Use mock.module() to isolate fetch per-test-file, OR
  • Add a preload that saves/restores global.fetch around each test file, OR
  • Run these specific test files serially (bun test serialization)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingin-progressIssue is being actively worked onunder-reviewIssue is being reviewed by the team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions