Skip to content

Commit

Permalink
Fix: Ensure full content is read before performing assertions
Browse files Browse the repository at this point in the history
This commit addresses the issue raised in the pull request apache#4989, where the `read()` operation did not always return the expected content length.

Changes include:
- Implementing a loop to gather all content chunks until EOF.
- Performing the assertion after the entire content has been read.

This ensures that the test passes stably by correctly handling cases where `read()` may not return the full content in one go.
  • Loading branch information
Bicheka committed Aug 11, 2024
1 parent 19b2f92 commit 69031ee
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions bindings/python/tests/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,27 @@ def test_sync_reader(service_name, operator, async_operator):
assert not reader.writable()
assert not reader.closed

read_content = reader.read()
read_content = bytearray()
while True:
chunk = reader.read(1024) # Read in chunks, e.g., 1024 bytes at a time
if not chunk:
break
read_content.extend(chunk)

read_content = bytes(read_content)
assert read_content is not None
assert read_content == content

with operator.open(filename, "rb") as reader:
read_content = reader.read(size + 1)
assert read_content is not None
assert read_content == content
read_content_eof = b""
read_content = bytearray()
while True:
chunk = reader.read(size)
chunk = reader.read(size + 1)
if not chunk:
break
read_content_eof += chunk
read_content.extend(chunk)

read_content = bytes(read_content)
assert read_content is not None
assert read_content == content

buf = bytearray(1)
Expand Down

0 comments on commit 69031ee

Please sign in to comment.