Refactor async PyMongoProtocol tests to use public read() API instead of _pending_messages

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Python Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Background

      test/asynchronous/test_async_network_layer.py has two tests that directly append to protocol._pending_messages (a private deque) to stage state before exercising buffer_updated and close:

      • test_buffer_updated_completes_pending_future (line 105)
      • test_close_with_exception_propagates_to_pending (line 115)

      Problem

      This is white-box coupling to an internal data structure. If _pending_messages is ever replaced with a different internal mechanism (e.g., a dict keyed by request ID), these tests break even though the observable behaviour of PyMongoProtocol is unchanged.

      Fix

      Replace the direct _pending_messages.append(future) setup with calls to protocol.read(), which enqueues the waiter through the public API and makes the tests resilient to internal refactors.

      Discovery

      Found during code review of PR #2774 (coverage increase for network_layer.py).

            Assignee:
            Unassigned
            Reporter:
            Alex Clark
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: