Skip to content

fix: improve test isolation in graphql-mesh-server maintenance tests#1511

Merged
daniel-vdp merged 2 commits into
mainfrom
fix/graphql-mesh-server-test
Jul 23, 2025
Merged

fix: improve test isolation in graphql-mesh-server maintenance tests#1511
daniel-vdp merged 2 commits into
mainfrom
fix/graphql-mesh-server-test

Conversation

@daniel-vdp

Copy link
Copy Markdown
Contributor

Summary

  • Fixed flaky test failures in graphql-mesh-server package by improving test isolation
  • Changed beforeAll to beforeEach in both maintenance test files
  • Ensures proper state reset between tests that share file system resources

Problem

The maintenance tests in graphql-mesh-server were failing intermittently in CI due to race conditions and shared file system state between tests. The whitelist test expected to find a complete IP allowlist but was only receiving a single IP address, indicating test interference.

Root Cause

  • Tests were using beforeAll hooks to set up file system state
  • Multiple tests sharing the same maintenance file were interfering with each other
  • Test execution order and parallel execution caused inconsistent results

Solution

Changed both test files to use beforeEach instead of beforeAll:

  • whitelist.test.ts: Reset whitelist state before each test
  • maintenance.test.ts: Reset maintenance status before each test

This ensures complete test isolation and prevents shared state issues.

Test Plan

  • All graphql-mesh-server tests pass locally
  • Both maintenance tests pass individually
  • Both maintenance tests pass together
  • Linting passes
  • Tests demonstrate proper isolation (no more race conditions)

Verification

yarn nx test graphql-mesh-server
# ✓ All tests pass consistently

🤖 Generated with Claude Code

- Changed beforeAll to beforeEach in whitelist.test.ts to ensure proper test isolation
- Changed beforeAll to beforeEach in maintenance.test.ts to ensure proper test isolation
- Prevents test interference when tests share file system state
- Fixes flaky test failures in CI pipeline

The issue was that tests were sharing file system state without proper reset
between tests, causing race conditions and inconsistent results in different
execution environments.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@daniel-vdp daniel-vdp requested a review from a team as a code owner July 22, 2025 06:18
@daniel-vdp daniel-vdp requested review from hubertott and porhkz July 22, 2025 06:18
- Added proper file cleanup in beforeEach hooks to prevent race conditions
- Fixed test dependency by setting up required state within individual tests
- Ensures tests can run independently without relying on execution order
- Fixes JSON parsing errors caused by corrupted files from concurrent access

This addresses the remaining CI failures where tests were interfering with
each other's file system state, causing "Unexpected end of JSON input" errors.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

@crispy101 crispy101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@daniel-vdp daniel-vdp merged commit 101e710 into main Jul 23, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants