def test_multiple_clients(mongo_container):
    """Test using multiple chat store instances with the same database."""
    # Create two chat store instances
    chat_store1 = MongoChatStore(
        mongo_uri=mongo_container["mongodb_uri"],
        db_name="test_multi_client_db",
        collection_name="test_chats",
    )

    chat_store2 = MongoChatStore(
        mongo_uri=mongo_container["mongodb_uri"],
        db_name="test_multi_client_db",
        collection_name="test_chats",
    )

    # Add message with first client
    key = "test_multi_client"
    chat_store1.set_messages(
        key=key, messages=[ChatMessage(role="user", content="Message from client 1")]
    )

    # Add message with second client
    chat_store2.add_message(
        key=key, message=ChatMessage(role="assistant", content="Message from client 2")
    )

    # Verify both messages are visible to both clients
    messages1 = chat_store1.get_messages(key=key)
    messages2 = chat_store2.get_messages(key=key)

    assert len(messages1) == 2
    assert len(messages2) == 2
    assert messages1[0].content == "Message from client 1"
    assert messages1[1].content == "Message from client 2"

    # Clean up
    chat_store1._collection.drop()
Test using multiple chat store instances with the same database.
llama-index-integrations/storage/chat_store/llama-index-storage-chat-store-mongo/tests/test_chat_store_mongo_chat_store.py