Skip to content

Commit

Permalink
fix edge case in logic and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abhiaagarwal authored and ion-elgreco committed Jun 19, 2024
1 parent ba352a7 commit f5696dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 3 additions & 1 deletion python/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ impl ObjectOutputStream {
// this will never overflow
let remaining = self.max_buffer_size - self.buffer.content_length();
// if we have enough space to store this chunk, just append it
if chunk.len() <= remaining {
if chunk.len() < remaining {
self.buffer.extend_from_slice(chunk);
break;
}
Expand All @@ -646,6 +646,8 @@ impl ObjectOutputStream {
self.upload_buffer()?;
// len(second) will always be < max_buffer_size, and we just
// emptied the buffer by flushing, so we won't overflow
// if len(chunk) just happened to be == remaining,
// the second slice is empty. this is a no-op
self.buffer.extend_from_slice(second);
}
Ok(len as i64)
Expand Down
18 changes: 12 additions & 6 deletions python/tests/test_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,18 @@ def test_roundtrip_azure_decoded_sas(azurite_sas_creds, sample_data: pa.Table):
assert dt.version() == 0


def test_warning_for_small_max_buffer_size(tmp_path):
for storage_size in [1, 4 * 1024 * 1024, 5 * 1024 * 1024 - 1]:
storage_opts = {"max_buffer_size": str(storage_size)}
store = DeltaStorageHandler(str(tmp_path.absolute()), options=storage_opts)
with pytest.warns(UserWarning):
store.open_output_stream("test")
@pytest.mark.parametrize("storage_size", [1, 4 * 1024 * 1024, 5 * 1024 * 1024 - 1])
def test_warning_for_small_max_buffer_size(tmp_path, storage_size):
storage_opts = {"max_buffer_size": str(storage_size)}
store = DeltaStorageHandler(str(tmp_path.absolute()), options=storage_opts)
with pytest.warns(UserWarning) as warnings:
store.open_output_stream("test")

assert len(warnings) == 1
assert (
f"You specified a `max_buffer_size` of {storage_size} bits less than {5*1024*1024} bits"
in str(warnings[0].message)
)


def test_pickle_roundtrip(tmp_path):
Expand Down

0 comments on commit f5696dc

Please sign in to comment.