Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple blocking binary reader issues #552

Merged
merged 5 commits into from
May 25, 2023

Conversation

nirosys
Copy link
Contributor

@nirosys nirosys commented May 16, 2023

Issue #, if available:

Description of changes:

  • Fixes an issue where read_from would read fewer bytes than it was expected to.
  • Addded incomplete guard to an annotation consume that could cause an error when the buffer did not have enough data.
  • Fixed an issue where bytes read into a NBR were counted twice when determining if all data had been read. This probably wasn't an issue since read_from reads all of the data requested.
  • Implements stream completion for non-blocking binary reader.
  • Moves Expandable to the raw_reader module now that the binary raw reader is using it.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

- Fixes an issue where `read_from` would read fewer bytes than it was expected to.
- Addded incomplete guard to an annotation consume that could cause an error
  when the buffer did not have enough data.
- Fixed an issue where bytes read into a NBR were counted twice when determining
  if all data had been read. This probably wasn't an issue since `read_from`
  reads all of the data requested.
- Implements stream completion for non-blocking binary reader.
- Moves Expandable to the raw_reader module now that the binary raw reader is using it.
@nirosys nirosys marked this pull request as ready for review May 16, 2023 18:38
@nirosys nirosys requested a review from zslayton May 16, 2023 18:38
@codecov
Copy link

codecov bot commented May 16, 2023

Codecov Report

Patch coverage: 93.63% and project coverage change: +0.04 🎉

Comparison is base (5e9fc59) 83.21% compared to head (f45cc8b) 83.25%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #552      +/-   ##
==========================================
+ Coverage   83.21%   83.25%   +0.04%     
==========================================
  Files          86       86              
  Lines       16455    16537      +82     
  Branches    16455    16537      +82     
==========================================
+ Hits        13693    13768      +75     
- Misses       1562     1563       +1     
- Partials     1200     1206       +6     
Impacted Files Coverage Δ
src/text/non_blocking/raw_text_reader.rs 79.22% <ø> (-0.11%) ⬇️
src/blocking_reader.rs 76.08% <90.32%> (+1.31%) ⬆️
src/binary/non_blocking/binary_buffer.rs 94.08% <92.30%> (-0.09%) ⬇️
src/binary/non_blocking/raw_binary_reader.rs 80.27% <95.00%> (+0.40%) ⬆️
src/raw_reader.rs 79.34% <100.00%> (+1.44%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@zslayton zslayton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff looks good! Could you add unit tests that cover the corner cases this addresses?

@nirosys
Copy link
Contributor Author

nirosys commented May 18, 2023

The diff looks good! Could you add unit tests that cover the corner cases this addresses?

Absolutely, I'll try to push those up tomorrow.

@nirosys
Copy link
Contributor Author

nirosys commented May 25, 2023

Pushed up some unit tests:

read_from reading fewer bytes, and potentially panicking.

Pre-PR:

thread 'binary::non_blocking::binary_buffer::tests::validate_read_from_size' panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `11`', src/binary/non_blocking/binary_buffer.rs:821:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test binary::non_blocking::binary_buffer::tests::validate_read_from_size ... FAILED

failures:

failures:
    binary::non_blocking::binary_buffer::tests::validate_read_from_size

Post PR:

test binary::non_blocking::binary_buffer::tests::validate_read_from_size ... ok

Processing annotation bytes leading to panic from BinaryBuffer over-consume.

Pre-PR:

thread 'binary::non_blocking::raw_binary_reader::tests::test_incomplete_annotation_wrapper' panicked at 'assertion failed: num_bytes_to_consume <= self.remaining()', src/binary/non_blocking/binary_buffer.rs:121:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test binary::non_blocking::raw_binary_reader::tests::test_incomplete_annotation_wrapper ... FAILED

failures:

failures:
    binary::non_blocking::raw_binary_reader::tests::test_incomplete_annotation_wrapper

Post PR:

test binary::non_blocking::raw_binary_reader::tests::test_incomplete_annotation_wrapper ... ok

End of Stream implementation in binary reader.

Pre-PR:

thread 'blocking_reader::tests::test_binary_end_of_stream' panicked at 'assertion failed: `(left == right)`
  left: `Value(Bool)`,
 right: `Nothing`', src/blocking_reader.rs:561:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test blocking_reader::tests::test_binary_end_of_stream ... FAILED

failures:

failures:
    blocking_reader::tests::test_binary_end_of_stream

Post-PR:

test blocking_reader::tests::test_binary_end_of_stream ... ok

Copy link
Contributor

@zslayton zslayton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to have this fixed, thanks!

src/binary/non_blocking/binary_buffer.rs Outdated Show resolved Hide resolved
@zslayton zslayton merged commit 7eed0eb into amazon-ion:main May 25, 2023
18 checks passed
@nirosys nirosys deleted the rgiliam/blocking_reader_fixes branch April 24, 2024 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants