Skip to content

Improve uploadRaceCondition.test.ts to verify truly concurrent asset writesΒ #2472

@AbanoubGhadban

Description

@AbanoubGhadban

Problem

The current uploadRaceCondition.test.ts uses a preHandler barrier to ensure both requests' onFile phases complete before either route handler runs. This proves that per-request upload directories prevent cross-contamination, but it doesn't guarantee that the actual asset copy operations inside the route handlers happen concurrently.

Because the barrier only synchronizes at the preHandler stage (after file upload, before handler execution), the route handlers may still execute sequentially in practice β€” one fully completing its lock-acquire β†’ copy β†’ unlock cycle before the other starts. This means the test may not exercise the per-bundle locking under true contention.

Suggested Improvement

Add a mechanism to verify that the critical sections (asset copy operations) overlap in time. For example:

  1. Instrument the lock/copy path with timestamps or counters to confirm both handlers hold or contend for locks simultaneously
  2. Add a second barrier inside the handler (e.g., after lock acquisition but before copy) to force true overlap of the copy phase
  3. Use a slow/large asset file to increase the window for overlap, combined with timing assertions

This would make the concurrency tests more robust and ensure the shared per-bundle lock is actually tested under contention rather than just sequential execution behind a barrier.

πŸ€– Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions