Skip to content

fix: improve BookingReferenceRepository integration test isolation#26707

Merged
keithwillcode merged 1 commit intomainfrom
devin/fix-flaky-booking-reference-tests-1768081177
Jan 11, 2026
Merged

fix: improve BookingReferenceRepository integration test isolation#26707
keithwillcode merged 1 commit intomainfrom
devin/fix-flaky-booking-reference-tests-1768081177

Conversation

@keithwillcode
Copy link
Contributor

What does this PR do?

Fixes flaky integration tests in BookingReferenceRepository.integration-test.ts that were introduced by commit eecf9e1. The tests were failing with ForeignKeyConstraintViolation errors (Prisma error P2003) on the BookingReference_bookingId_fkey constraint.

Root cause: The tests created a single booking in beforeAll that was shared across all tests. This caused race conditions when tests run in parallel - one test's cleanup could delete the booking while another test was still trying to use it.

Fix:

  • Use seed user (member0-acme@example.com) when available in CI, with fallback to creating a test user for local development
  • Move booking creation from beforeAll to beforeEach so each test gets a fresh, isolated booking
  • Track created bookings and clean them up properly in afterEach
  • Fix import organization to satisfy linter

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. N/A - test-only changes.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  1. CI should pass - the integration tests that were previously flaky should now pass consistently
  2. Run the integration tests locally multiple times to verify stability:
    set -a && source .env && set +a
    VITEST_MODE=integration TZ=UTC yarn test packages/features/bookingReference/repositories/BookingReferenceRepository.integration-test.ts
  3. All 9 tests in the file should pass consistently across multiple runs

Checklist

  • I have read the contributing guide
  • My code follows the style guidelines of this project
  • I have checked if my changes generate no new warnings

Reviewer notes:

  • Verify the import change from import prisma from "@calcom/prisma" to import { prisma } from "@calcom/prisma" is correct
  • The seed user fallback creates a test user that isn't explicitly cleaned up if the seed user doesn't exist - this is acceptable since it only happens in local dev

Requested by: @keithwillcode
Link to Devin run: https://app.devin.ai/sessions/a4fb71e0632041b28f8ed19205b96cf9

The integration tests were flaky because they relied on a shared booking
created in beforeAll, which could cause race conditions when tests run
in parallel or when cleanup from previous runs interfered.

Changes:
- Use seed user (member0-acme@example.com) when available, fallback to
  creating a test user for local development
- Create a fresh booking in beforeEach instead of sharing one across tests
- Track created bookings and clean them up properly in afterEach
- Fix import organization to satisfy linter

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@keithwillcode keithwillcode self-assigned this Jan 10, 2026
@keithwillcode keithwillcode added this to the v6.1 milestone Jan 10, 2026
@keithwillcode keithwillcode marked this pull request as ready for review January 10, 2026 22:18
@graphite-app graphite-app bot added the core area: core, team members only label Jan 10, 2026
@graphite-app graphite-app bot requested a review from a team January 10, 2026 22:18
@keithwillcode keithwillcode enabled auto-merge (squash) January 10, 2026 22:18
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

@keithwillcode keithwillcode merged commit 539214b into main Jan 11, 2026
75 of 78 checks passed
@keithwillcode keithwillcode deleted the devin/fix-flaky-booking-reference-tests-1768081177 branch January 11, 2026 04:31
Anshumancanrock pushed a commit to Anshumancanrock/cal.com that referenced this pull request Jan 12, 2026
…alcom#26707)

The integration tests were flaky because they relied on a shared booking
created in beforeAll, which could cause race conditions when tests run
in parallel or when cleanup from previous runs interfered.

Changes:
- Use seed user (member0-acme@example.com) when available, fallback to
  creating a test user for local development
- Create a fresh booking in beforeEach instead of sharing one across tests
- Track created bookings and clean them up properly in afterEach
- Fix import organization to satisfy linter

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@vercel vercel bot temporarily deployed to Preview – cal-companion January 13, 2026 08:25 Inactive
@vercel vercel bot temporarily deployed to Preview – dev January 13, 2026 08:25 Inactive
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.

2 participants