Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
pitrou committed Jun 10, 2024
1 parent ab1d3b1 commit 54463ca
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions cpp/src/arrow/filesystem/s3fs_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,26 @@ class TestS3FS : public S3TestMixin {
// after CloseAsync or synchronously after stream.reset() since we're just
// checking that `closeAsyncFut` keeps the stream alive until completion
// rather than segfaulting on a dangling stream
auto closeAsyncFut = stream->CloseAsync();
auto close_fut = stream->CloseAsync();
stream.reset();
ASSERT_OK(closeAsyncFut.MoveResult());
ASSERT_OK(close_fut.MoveResult());
AssertObjectContents(client_.get(), "bucket", "somefile", "new data");
}

void TestOpenOutputStreamCloseAsyncFutureDeadlock() {
// This is inspired by GH-41862, though it fails to reproduce the actual
// issue reported there (actual preconditions might be required).
// Here we lose our reference to an output stream from its CloseAsync callback.
// This should not deadlock.
std::shared_ptr<io::OutputStream> stream;
ASSERT_OK_AND_ASSIGN(stream, fs_->OpenOutputStream("bucket/somefile"));
ASSERT_OK(stream->Write("new data"));
auto close_fut = stream->CloseAsync();
close_fut.AddCallback([stream = std::move(stream)](Status st) mutable {
// Trigger stream destruction from callback
stream.reset();
});
ASSERT_OK(close_fut.MoveResult());
AssertObjectContents(client_.get(), "bucket", "somefile", "new data");
}

Expand Down Expand Up @@ -1254,6 +1271,16 @@ TEST_F(TestS3FS, OpenOutputStreamAsyncDestructorSyncWrite) {
TestOpenOutputStreamCloseAsyncDestructor();
}

TEST_F(TestS3FS, OpenOutputStreamCloseAsyncFutureDeadlockBackgroundWrites) {
TestOpenOutputStreamCloseAsyncFutureDeadlock();
}

TEST_F(TestS3FS, OpenOutputStreamCloseAsyncFutureDeadlockSyncWrite) {
options_.background_writes = false;
MakeFileSystem();
TestOpenOutputStreamCloseAsyncFutureDeadlock();
}

TEST_F(TestS3FS, OpenOutputStreamMetadata) {
std::shared_ptr<io::OutputStream> stream;

Expand Down

0 comments on commit 54463ca

Please sign in to comment.