fix(PageBufferReader): PageBufferReader should conform to Reader interface #1935
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Fixes DGRAPHCORE-121
The CI build was showing sporadic failures of TestPagebufferReader2 with the error message:
Received unexpected error: EOF
The result is sporadic because the test case relied on randomized behavior. In particular, it would
generate a read-buffer of some random length, which could occasionally have a length of 0.
When the length is 0, we would encounter this error.
The cause is from the PageBufferReader having incorrect behavior for the Read(p []byte) function: In particular, when p is empty, based on the expected behavior of the Reader interface, this should return 0, nil. However, this is currently returning 0, EOF.
Solution
First:
I added a unit test to make sure we consider the empty buffer input in every case (instead of just randomly every once in a while). This doesn't actually provide a solution, but it makes sure that we don't end up with a regression in this area.
Second:
At the point where we currently detect that we read 0 bytes, before just returning 0, EOF, I add a check to make sure that the value p has non-zero length.