Skip to content

[TESTING] Add concurrent access and race condition tests #45

@7tg

Description

@7tg

Description

Missing test coverage for concurrent access scenarios and race conditions.

Missing Tests

Concurrent CRUD Tests

  • test_concurrent_delete_same_object - Two requests delete same object
  • test_concurrent_update_same_object - Two requests update same object
  • test_concurrent_bulk_update_same_items - Bulk updates to same objects
  • test_inline_update_parent_deleted_concurrently - Parent deleted during inline update

Token Concurrency Tests

  • test_token_last_used_with_concurrent_requests - Multiple simultaneous token uses
  • test_token_revocation_during_active_request - Token revoked mid-request

Transaction Tests

  • test_bulk_all_or_nothing_transaction - Verify bulk operation transaction semantics
  • test_create_rollback_on_log_failure - Object not created if logging fails
  • test_inline_rollback_on_partial_failure - Inline failures rollback parent

Example Test

import asyncio
import pytest

@pytest.mark.django_db(transaction=True)
@pytest.mark.asyncio
async def test_concurrent_update_same_object(article, token, async_client):
    """Verify concurrent updates don't corrupt data."""
    async def update_title(new_title):
        return await async_client.post(
            "/mcp/",
            json={
                "method": "tools/call",
                "params": {
                    "name": "update_article",
                    "arguments": {"id": article.id, "data": {"title": new_title}}
                }
            },
            headers={"Authorization": f"Bearer {token.token}"}
        )
    
    # Launch concurrent updates
    results = await asyncio.gather(
        update_title("Title A"),
        update_title("Title B"),
        return_exceptions=True
    )
    
    # Verify one succeeded and data is consistent
    article.refresh_from_db()
    assert article.title in ["Title A", "Title B"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions