@@ -837,6 +837,73 @@ TEST(AsyncWriterConnectionTest, QueryUpdatesHandle) {
837837 EXPECT_EQ (seen_handles[0 ], " queried-handle" );
838838}
839839
840+ TEST (AsyncWriterConnectionTest, CloseEmpty) {
841+ AsyncSequencer<bool > sequencer;
842+ auto mock = std::make_unique<MockStream>();
843+ EXPECT_CALL (*mock, Cancel).Times (1 );
844+ EXPECT_CALL (*mock, Write)
845+ .WillOnce ([&](Request const & request, grpc::WriteOptions wopt) {
846+ EXPECT_TRUE (request.flush ());
847+ EXPECT_TRUE (request.state_lookup ());
848+ EXPECT_TRUE (wopt.is_last_message ());
849+ EXPECT_EQ (request.common_object_request_params ().encryption_algorithm (),
850+ " test-only-algo" );
851+ return sequencer.PushBack (" Write" );
852+ });
853+ EXPECT_CALL (*mock, Finish).WillOnce ([&] {
854+ return sequencer.PushBack (" Finish" ).then ([](auto f) {
855+ if (f.get ()) return Status{};
856+ return PermanentError ();
857+ });
858+ });
859+ auto hash = std::make_shared<MockHashFunction>();
860+ EXPECT_CALL (*hash, Update (_, An<absl::Cord const &>(), _)).Times (1 );
861+ EXPECT_CALL (*hash, Finish).Times (0 );
862+
863+ auto tested = std::make_unique<AsyncWriterConnectionImpl>(
864+ TestOptions (), MakeRequest (), std::move (mock), hash, 1024 );
865+ auto close = tested->Close (WritePayload{});
866+ auto next = sequencer.PopFrontWithName ();
867+ ASSERT_THAT (next.second , " Write" );
868+ next.first .set_value (true );
869+
870+ next = sequencer.PopFrontWithName ();
871+ ASSERT_THAT (next.second , " Finish" );
872+ next.first .set_value (true );
873+
874+ EXPECT_THAT (close.get (), IsOk ());
875+ tested = {};
876+ }
877+
878+ TEST (AsyncWriterConnectionTest, CloseError) {
879+ AsyncSequencer<bool > sequencer;
880+ auto mock = std::make_unique<MockStream>();
881+ EXPECT_CALL (*mock, Cancel).Times (1 );
882+ EXPECT_CALL (*mock, Write).WillOnce ([&](Request const &, grpc::WriteOptions) {
883+ return sequencer.PushBack (" Write" );
884+ });
885+ EXPECT_CALL (*mock, Finish).WillOnce ([&] {
886+ return sequencer.PushBack (" Finish" ).then ([](auto f) {
887+ if (f.get ()) return Status{};
888+ return PermanentError ();
889+ });
890+ });
891+ auto hash = std::make_shared<MockHashFunction>();
892+ EXPECT_CALL (*hash, Update (_, An<absl::Cord const &>(), _)).Times (1 );
893+ EXPECT_CALL (*hash, Finish).Times (0 );
894+
895+ auto tested = std::make_unique<AsyncWriterConnectionImpl>(
896+ TestOptions (), MakeRequest (), std::move (mock), hash, 1024 );
897+ auto response = tested->Close (WritePayload{});
898+ auto next = sequencer.PopFrontWithName ();
899+ ASSERT_THAT (next.second , " Write" );
900+ next.first .set_value (false ); // Detect an error on Write()
901+ next = sequencer.PopFrontWithName ();
902+ ASSERT_THAT (next.second , " Finish" );
903+ next.first .set_value (false ); // Return error from Finish()
904+ EXPECT_THAT (response.get (), StatusIs (PermanentError ().code ()));
905+ }
906+
840907GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
841908} // namespace storage_internal
842909} // namespace cloud
0 commit comments