@@ -67,15 +67,18 @@ auto constexpr kMetadataText = R"pb(
6767
6868auto NoResume () { return storage::LimitedErrorCountResumePolicy (0 )(); }
6969
70- auto MakeTested (std::unique_ptr<storage::ResumePolicy> resume_policy,
71- OpenStreamFactory make_stream,
72- google::storage::v2::BidiReadObjectSpec read_object_spec,
73- std::shared_ptr<OpenStream> stream) {
70+ auto MakeTested (
71+ std::unique_ptr<storage::ResumePolicy> resume_policy,
72+ OpenStreamFactory make_stream,
73+ google::storage::v2::BidiReadObjectSpec read_object_spec,
74+ std::shared_ptr<OpenStream> stream,
75+ std::function<bool ()> transport_ok = [] { return true ; }) {
7476 Options options;
7577 options.set <storage::EnableMultiStreamOptimizationOption>(true );
7678 return std::make_shared<ObjectDescriptorImpl>(
7779 std::move (resume_policy), std::move (make_stream),
78- std::move (read_object_spec), std::move (stream), std::move (options));
80+ std::move (read_object_spec), std::move (stream), std::move (options),
81+ std::move (transport_ok));
7982}
8083
8184MATCHER_P (IsProtoEqualModuloRepeatedFieldOrdering, value,
@@ -1784,6 +1787,83 @@ TEST(ObjectDescriptorImpl, MultiStreamOptimizationDisabled) {
17841787 tested.reset ();
17851788}
17861789
1790+ // / @test Verify that IsOpen() is true by default.
1791+ TEST (ObjectDescriptorImpl, IsOpenTrueByDefault) {
1792+ MockFactory factory;
1793+ auto stream = std::make_unique<MockStream>();
1794+ EXPECT_CALL (*stream, Finish).WillOnce (Return (make_ready_future (Status{})));
1795+ EXPECT_CALL (*stream, Cancel).Times (AtMost (1 ));
1796+ auto tested = MakeTested (NoResume (), factory.AsStdFunction (),
1797+ google::storage::v2::BidiReadObjectSpec{},
1798+ std::make_shared<OpenStream>(std::move (stream)));
1799+ EXPECT_TRUE (tested->IsOpen ());
1800+ }
1801+
1802+ // / @test Verify that IsOpen() is false after Cancel().
1803+ TEST (ObjectDescriptorImpl, IsOpenFalseOnCancel) {
1804+ MockFactory factory;
1805+ auto stream = std::make_unique<MockStream>();
1806+ EXPECT_CALL (*stream, Finish).WillOnce (Return (make_ready_future (Status{})));
1807+ EXPECT_CALL (*stream, Cancel).Times (AtMost (2 ));
1808+ auto tested = MakeTested (NoResume (), factory.AsStdFunction (),
1809+ google::storage::v2::BidiReadObjectSpec{},
1810+ std::make_shared<OpenStream>(std::move (stream)));
1811+ EXPECT_TRUE (tested->IsOpen ());
1812+ tested->Cancel ();
1813+ EXPECT_FALSE (tested->IsOpen ());
1814+ }
1815+
1816+ // / @test Verify that IsOpen() is false if transport health check fails.
1817+ TEST (ObjectDescriptorImpl, IsOpenFalseOnPermanentError) {
1818+ MockFactory factory;
1819+ auto stream = std::make_unique<MockStream>();
1820+ EXPECT_CALL (*stream, Finish).WillOnce (Return (make_ready_future (Status{})));
1821+ EXPECT_CALL (*stream, Cancel).Times (AtMost (1 ));
1822+ bool transport_ok = true ;
1823+ auto transport_ok_callback = [&transport_ok] { return transport_ok; };
1824+
1825+ auto tested = MakeTested (NoResume (), factory.AsStdFunction (),
1826+ google::storage::v2::BidiReadObjectSpec{},
1827+ std::make_shared<OpenStream>(std::move (stream)),
1828+ transport_ok_callback);
1829+
1830+ EXPECT_TRUE (tested->IsOpen ());
1831+ transport_ok = false ;
1832+ EXPECT_FALSE (tested->IsOpen ());
1833+ }
1834+
1835+ TEST (ObjectDescriptorImpl, IsOpenFalseOnTransportFailure) {
1836+ auto stream = std::make_unique<MockStream>();
1837+ EXPECT_CALL (*stream, Cancel).Times (1 );
1838+ EXPECT_CALL (*stream, Finish).WillOnce ([] {
1839+ return make_ready_future (Status{});
1840+ });
1841+ MockFactory factory;
1842+ auto transport_ok = [] { return false ; };
1843+ auto tested = std::make_shared<ObjectDescriptorImpl>(
1844+ NoResume (), factory.AsStdFunction (),
1845+ google::storage::v2::BidiReadObjectSpec{},
1846+ std::make_shared<OpenStream>(std::move (stream)), Options{},
1847+ std::move (transport_ok));
1848+ EXPECT_FALSE (tested->IsOpen ());
1849+ }
1850+
1851+ TEST (ObjectDescriptorImpl, IsOpenTrueOnTransportSuccess) {
1852+ auto stream = std::make_unique<MockStream>();
1853+ EXPECT_CALL (*stream, Cancel).Times (1 );
1854+ EXPECT_CALL (*stream, Finish).WillOnce ([] {
1855+ return make_ready_future (Status{});
1856+ });
1857+ MockFactory factory;
1858+ auto transport_ok = [] { return true ; };
1859+ auto tested = std::make_shared<ObjectDescriptorImpl>(
1860+ NoResume (), factory.AsStdFunction (),
1861+ google::storage::v2::BidiReadObjectSpec{},
1862+ std::make_shared<OpenStream>(std::move (stream)), Options{},
1863+ std::move (transport_ok));
1864+ EXPECT_TRUE (tested->IsOpen ());
1865+ }
1866+
17871867} // namespace
17881868GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
17891869} // namespace storage_internal
0 commit comments