-
Notifications
You must be signed in to change notification settings - Fork 518
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: Fix flush/close semantics for HTTP files, improve testing #1232
fix: Fix flush/close semantics for HTTP files, improve testing #1232
Conversation
All HTTP-based tests now use an embedded test server instead of httpbin.org, which makes them much faster and more reliable. These more reliable tests also exposed some issues that began recently with PR shaka-project#1201. HttpFile's Flush() semantics were different than those documented for files in general. Flush() used to close the file for uploading, so that no further writes were allowed, but the documentation stated that it would only flush data to its destination. PR shaka-project#1201 brought HttpFile's Flush() in line with the docs, but gave us no way to terminate a chunked upload. This adds a new method to File called CloseForWriting(), which terminates a chunked upload for HttpFile. The only other implementation that does anything is UdpFile, which uses the socket library function shutdown() to terminate writes while allowing reads. This also tweaks HttpFile::CloseWithStatus() so that it will not generate an error if the file is closed before the HTTP response is written to the download cache. This modifies the test HttpFileTest.MultipleWrites so that the file is Flushed after each chunk. This adds test coverage for the changes introduced in PR shaka-project#1201. Fixes shaka-project#1224 (missing test coverage for HttpFile::Flush)
a584a0e
to
2f67ac5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM % one question
packager/file/http_file_unittest.cc
Outdated
@@ -165,21 +214,35 @@ TEST(HttpFileTest, MultipleWrites) { | |||
|
|||
ASSERT_EQ(file->Write(data1.data(), data1.size()), | |||
static_cast<int64_t>(data1.size())); | |||
ASSERT_TRUE(file->Flush()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we call Flush after every write in this test? Is it needed after every write?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It adds coverage for the change in Flush() semantics from #1201. Now that Flush() only flushes, this shows the new behavior. Before #1201, you could not Write() after Flush().
In the test server, you can see those pieces written as separate chunks now. This isn't used yet, but it may be an important detail for chunked uploads for LL streaming in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. It is probably better to add another MultipleWritesWithFlush to test this case. Otherwise consecutive Writes without Flush is not tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
All HTTP-based tests now use an embedded test server instead of
httpbin.org, which makes them much faster and more reliable.
These more reliable tests also exposed some issues that began recently
with PR #1201. HttpFile's Flush() semantics were different than those
documented for files in general. Flush() used to close the file for
uploading, so that no further writes were allowed, but the documentation
stated that it would only flush data to its destination. PR #1201
brought HttpFile's Flush() in line with the docs, but gave us no way to
terminate a chunked upload.
This adds a new method to File called CloseForWriting(), which
terminates a chunked upload for HttpFile. The only other implementation
that does anything is UdpFile, which uses the socket library function
shutdown() to terminate writes while allowing reads.
This also tweaks HttpFile::CloseWithStatus() so that it will not
generate an error if the file is closed before the HTTP response is
written to the download cache.
This modifies the test HttpFileTest.MultipleWrites so that the file is
Flushed after each chunk. This adds test coverage for the changes
introduced in PR #1201.
Fixes #1224 (missing test coverage for HttpFile::Flush)