Skip to content

Commit 1f0b50b

Browse files
committed
fix: log warning for unregistered read_id in stream multiplexer
Added a warning log when the stream multiplexer receives data for an unregistered read_id, and updated the corresponding test to verify the logging behavior. Also applied linter formatting to the modified files.
1 parent 7c6fee2 commit 1f0b50b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

packages/google-cloud-storage/google/cloud/storage/asyncio/_stream_multiplexer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
from __future__ import annotations
1616

1717
import asyncio
18-
import grpc
1918
import logging
2019
from typing import Awaitable, Callable, Dict, Optional, Set
2120

21+
import grpc
22+
2223
from google.cloud import _storage_v2
2324
from google.cloud.storage.asyncio.async_read_object_stream import (
2425
_AsyncReadObjectStream,
@@ -139,6 +140,10 @@ async def _recv_loop(self) -> None:
139140
queue = self._queues.get(read_id)
140141
if queue:
141142
queues_to_notify.add(queue)
143+
else:
144+
logger.warning(
145+
f"Received data for unregistered read_id: {read_id}"
146+
)
142147
await asyncio.gather(
143148
*(
144149
self._put_with_timeout(queue, response)

packages/google-cloud-storage/tests/unit/asyncio/test_stream_multiplexer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
# limitations under the License.
1414

1515
import asyncio
16-
import grpc
1716
from unittest.mock import AsyncMock
1817

18+
import grpc
1919
import pytest
2020

2121
from google.cloud import _storage_v2
@@ -325,7 +325,7 @@ async def test_error_uses_put_nowait(self):
325325
assert err.exception is exc
326326

327327
@pytest.mark.asyncio
328-
async def test_unknown_read_id_is_dropped(self):
328+
async def test_unknown_read_id_is_dropped(self, caplog):
329329
# Given a multiplexer and a response with an unknown read ID
330330
mock_stream = AsyncMock()
331331
resp = _make_response(read_id=999)
@@ -341,6 +341,9 @@ async def test_unknown_read_id_is_dropped(self):
341341
end = await asyncio.wait_for(queue.get(), timeout=1)
342342
assert isinstance(end, _StreamEnd)
343343

344+
# And a warning is logged
345+
assert "Received data for unregistered read_id: 999" in caplog.text
346+
344347

345348
class TestSend:
346349
@pytest.mark.asyncio

0 commit comments

Comments
 (0)