Repository navigation
Closed
Description
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 ... FAILEDReproduction
Concurrent execution (default - FAILS):
cargo test --package nodespace-core --lib
# Result: 2 tests failIndividual 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
test_complex_heading_transitions- Added in Fix create_nodes_from_markdown hierarchy: Same-level headers incorrectly nested #352test_move_child_to_index_beyond_sibling_count- Added in Add index-based child operations and fix sibling chain integrity #339- Both PRs claimed all tests passing at merge (likely ran individually)
- Race conditions only manifest when running full test suite concurrently
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
-
Identify shared resources:
- Review both test files for database access patterns
- Check for static/global state usage
- Look for temp file/directory conflicts
-
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
-
Common patterns to check:
staticvariables 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
- Investigate SIGABRT/SIGTRAP crash when running full Rust test suite #398
- Replace hardcoded behavior validation with schema-driven validation #392
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_transitionspackages/core/src/mcp/handlers/markdown.rs- Implementationpackages/core/src/mcp/handlers/nodes_test.rs- test_move_child_to_index_beyond_sibling_countpackages/core/src/mcp/handlers/nodes.rs- Implementation
Activity