Skip to content

Fix test isolation issue: 2 tests fail concurrently but pass individually #402

Closed

Description

@malibio

Problem

Two Rust backend tests fail when run concurrently but pass when run individually. This indicates a test isolation issue where tests are sharing state or resources improperly.

Failing Tests (Concurrent Only)

test mcp::handlers::markdown::markdown_test::tests::test_complex_heading_transitions ... FAILED
test mcp::handlers::nodes::nodes_test::integration_tests::test_move_child_to_index_beyond_sibling_count ... FAILED

Reproduction

Concurrent execution (default - FAILS):

cargo test --package nodespace-core --lib
# Result: 2 tests fail

Individual execution (PASSES):

cargo test --package nodespace-core test_complex_heading_transitions
cargo test --package nodespace-core test_move_child_to_index_beyond_sibling_count
# Result: Both pass ✅

Single-threaded execution (PASSES):

cargo test --package nodespace-core --lib -- --test-threads=1
# Result: Both pass ✅

Root Cause

These tests have race conditions due to:

  • Shared state between tests (global variables, static state)
  • Database connection conflicts
  • File system resources (temp files, database files)
  • Test setup/teardown not properly isolated

History

Impact

  • Tests are flaky - fail randomly depending on execution order
  • Reduces confidence in test suite
  • Makes CI/CD unreliable
  • Developer friction when running full test suite

Investigation Steps

  1. Identify shared resources:

    • Review both test files for database access patterns
    • Check for static/global state usage
    • Look for temp file/directory conflicts
  2. Add proper isolation:

    • Ensure unique database names per test
    • Clean up resources in test teardown
    • Use test-specific temp directories
    • Add proper setup/teardown hooks
  3. Common patterns to check:

    • static variables shared across tests
    • Database connections not properly closed
    • Test fixtures not cleaned up
    • Race conditions in async test setup

Acceptance Criteria

  • Both tests pass consistently when run concurrently with full test suite
  • Tests pass 100 times in a row: for i in {1..100}; do cargo test --package nodespace-core --lib || break; done
  • Root cause documented in commit message
  • Proper test isolation implemented (unique resources per test)
  • No new warnings or clippy issues

Related Issues

Priority

🔴 HIGH - Flaky tests reduce confidence in the test suite and indicate potential production race conditions.

Technical Specifications

Reference Files

  • packages/core/src/mcp/handlers/markdown_test.rs - test_complex_heading_transitions
  • packages/core/src/mcp/handlers/markdown.rs - Implementation
  • packages/core/src/mcp/handlers/nodes_test.rs - test_move_child_to_index_beyond_sibling_count
  • packages/core/src/mcp/handlers/nodes.rs - Implementation

Activity

  1. added
    bug
    on Nov 4, 2025
  2. self-assigned this
    on Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

backendbugrusttesting

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions