[pkg/stanza] Fix flaky TestDeleteAfterRead_SkipPartials #29597
Merged
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.
Fixes #27845
The failure mechanism was very subtle. The test waits for the contents of the short file to be emitted before canceling the context which is used in the file reader. However, the reader may require one additional scan to determine that it's reached the end of the file, and therefore in a tiny proportion of cases, the context cancelation could actually trigger the reader to return before it had determined it should delete the file. The solution involves validating file deletion before canceling the context. I was able to reproduce failure locally only about 1/3000 times, but with this change was able to run 30,000 times without a failure. The PR also cleans up a few related parts of the code.