diff options
Diffstat (limited to 'src/test/librados/asio.cc')
-rw-r--r-- | src/test/librados/asio.cc | 121 |
1 files changed, 73 insertions, 48 deletions
diff --git a/src/test/librados/asio.cc b/src/test/librados/asio.cc index 9f8844eb7bb..01ebb957150 100644 --- a/src/test/librados/asio.cc +++ b/src/test/librados/asio.cc @@ -28,8 +28,6 @@ #define dout_subsys ceph_subsys_rados #define dout_context g_ceph_context -using namespace std; - // test fixture for global setup/teardown class AsioRados : public ::testing::Test { static constexpr auto poolname = "ceph_test_rados_api_asio"; @@ -73,6 +71,9 @@ librados::Rados AsioRados::rados; librados::IoCtx AsioRados::io; librados::IoCtx AsioRados::snapio; +using boost::system::error_code; +using read_result = std::tuple<version_t, bufferlist>; + void rethrow(std::exception_ptr eptr) { if (eptr) std::rethrow_exception(eptr); } @@ -81,14 +82,17 @@ TEST_F(AsioRados, AsyncReadCallback) { boost::asio::io_context service; - auto success_cb = [&] (boost::system::error_code ec, bufferlist bl) { + auto success_cb = [&] (error_code ec, version_t ver, bufferlist bl) { EXPECT_FALSE(ec); + EXPECT_LT(0, ver); EXPECT_EQ("hello", bl.to_str()); }; librados::async_read(service, io, "exist", 256, 0, success_cb); - auto failure_cb = [&] (boost::system::error_code ec, bufferlist bl) { + auto failure_cb = [&] (error_code ec, version_t ver, bufferlist bl) { EXPECT_EQ(boost::system::errc::no_such_file_or_directory, ec); + EXPECT_EQ(0, ver); + EXPECT_EQ(0, bl.length()); }; librados::async_read(service, io, "noexist", 256, 0, failure_cb); @@ -99,17 +103,17 @@ TEST_F(AsioRados, AsyncReadFuture) { boost::asio::io_context service; - std::future<bufferlist> f1 = librados::async_read(service, io, "exist", 256, - 0, boost::asio::use_future); - std::future<bufferlist> f2 = librados::async_read(service, io, "noexist", 256, - 0, boost::asio::use_future); + auto f1 = librados::async_read(service, io, "exist", 256, + 0, boost::asio::use_future); + auto f2 = librados::async_read(service, io, "noexist", 256, + 0, boost::asio::use_future); service.run(); - EXPECT_NO_THROW({ - auto bl = f1.get(); - EXPECT_EQ("hello", bl.to_str()); - }); + auto [ver, bl] = f1.get(); + EXPECT_LT(0, ver); + EXPECT_EQ("hello", bl.to_str()); + EXPECT_THROW(f2.get(), boost::system::system_error); } @@ -118,17 +122,22 @@ TEST_F(AsioRados, AsyncReadYield) boost::asio::io_context service; auto success_cr = [&] (boost::asio::yield_context yield) { - boost::system::error_code ec; - auto bl = librados::async_read(service, io, "exist", 256, 0, yield[ec]); + error_code ec; + auto [ver, bl] = librados::async_read(service, io, "exist", 256, + 0, yield[ec]); EXPECT_FALSE(ec); + EXPECT_LT(0, ver); EXPECT_EQ("hello", bl.to_str()); }; boost::asio::spawn(service, success_cr, rethrow); auto failure_cr = [&] (boost::asio::yield_context yield) { - boost::system::error_code ec; - auto bl = librados::async_read(service, io, "noexist", 256, 0, yield[ec]); + error_code ec; + auto [ver, bl] = librados::async_read(service, io, "noexist", 256, + 0, yield[ec]); EXPECT_EQ(boost::system::errc::no_such_file_or_directory, ec); + EXPECT_EQ(0, ver); + EXPECT_EQ(0, bl.length()); }; boost::asio::spawn(service, failure_cr, rethrow); @@ -142,14 +151,16 @@ TEST_F(AsioRados, AsyncWriteCallback) bufferlist bl; bl.append("hello"); - auto success_cb = [&] (boost::system::error_code ec) { + auto success_cb = [&] (error_code ec, version_t ver) { EXPECT_FALSE(ec); + EXPECT_LT(0, ver); }; librados::async_write(service, io, "exist", bl, bl.length(), 0, success_cb); - auto failure_cb = [&] (boost::system::error_code ec) { + auto failure_cb = [&] (error_code ec, version_t ver) { EXPECT_EQ(boost::system::errc::read_only_file_system, ec); + EXPECT_EQ(0, ver); }; librados::async_write(service, snapio, "exist", bl, bl.length(), 0, failure_cb); @@ -171,7 +182,7 @@ TEST_F(AsioRados, AsyncWriteFuture) service.run(); - EXPECT_NO_THROW(f1.get()); + EXPECT_LT(0, f1.get()); EXPECT_THROW(f2.get(), boost::system::system_error); } @@ -183,19 +194,21 @@ TEST_F(AsioRados, AsyncWriteYield) bl.append("hello"); auto success_cr = [&] (boost::asio::yield_context yield) { - boost::system::error_code ec; - librados::async_write(service, io, "exist", bl, bl.length(), 0, - yield[ec]); + error_code ec; + auto ver = librados::async_write(service, io, "exist", bl, + bl.length(), 0, yield[ec]); EXPECT_FALSE(ec); + EXPECT_LT(0, ver); EXPECT_EQ("hello", bl.to_str()); }; boost::asio::spawn(service, success_cr, rethrow); auto failure_cr = [&] (boost::asio::yield_context yield) { - boost::system::error_code ec; - librados::async_write(service, snapio, "exist", bl, bl.length(), 0, - yield[ec]); + error_code ec; + auto ver = librados::async_write(service, snapio, "exist", bl, + bl.length(), 0, yield[ec]); EXPECT_EQ(boost::system::errc::read_only_file_system, ec); + EXPECT_EQ(0, ver); }; boost::asio::spawn(service, failure_cr, rethrow); @@ -208,8 +221,9 @@ TEST_F(AsioRados, AsyncReadOperationCallback) { librados::ObjectReadOperation op; op.read(0, 0, nullptr, nullptr); - auto success_cb = [&] (boost::system::error_code ec, bufferlist bl) { + auto success_cb = [&] (error_code ec, version_t ver, bufferlist bl) { EXPECT_FALSE(ec); + EXPECT_LT(0, ver); EXPECT_EQ("hello", bl.to_str()); }; librados::async_operate(service, io, "exist", &op, 0, nullptr, success_cb); @@ -217,8 +231,10 @@ TEST_F(AsioRados, AsyncReadOperationCallback) { librados::ObjectReadOperation op; op.read(0, 0, nullptr, nullptr); - auto failure_cb = [&] (boost::system::error_code ec, bufferlist bl) { + auto failure_cb = [&] (error_code ec, version_t ver, bufferlist bl) { EXPECT_EQ(boost::system::errc::no_such_file_or_directory, ec); + EXPECT_EQ(0, ver); + EXPECT_EQ(0, bl.length()); }; librados::async_operate(service, io, "noexist", &op, 0, nullptr, failure_cb); } @@ -228,14 +244,14 @@ TEST_F(AsioRados, AsyncReadOperationCallback) TEST_F(AsioRados, AsyncReadOperationFuture) { boost::asio::io_context service; - std::future<bufferlist> f1; + std::future<read_result> f1; { librados::ObjectReadOperation op; op.read(0, 0, nullptr, nullptr); f1 = librados::async_operate(service, io, "exist", &op, 0, nullptr, boost::asio::use_future); } - std::future<bufferlist> f2; + std::future<read_result> f2; { librados::ObjectReadOperation op; op.read(0, 0, nullptr, nullptr); @@ -244,10 +260,10 @@ TEST_F(AsioRados, AsyncReadOperationFuture) } service.run(); - EXPECT_NO_THROW({ - auto bl = f1.get(); - EXPECT_EQ("hello", bl.to_str()); - }); + auto [ver, bl] = f1.get(); + EXPECT_LT(0, ver); + EXPECT_EQ("hello", bl.to_str()); + EXPECT_THROW(f2.get(), boost::system::system_error); } @@ -258,10 +274,11 @@ TEST_F(AsioRados, AsyncReadOperationYield) auto success_cr = [&] (boost::asio::yield_context yield) { librados::ObjectReadOperation op; op.read(0, 0, nullptr, nullptr); - boost::system::error_code ec; - auto bl = librados::async_operate(service, io, "exist", &op, 0, nullptr, - yield[ec]); + error_code ec; + auto [ver, bl] = librados::async_operate(service, io, "exist", &op, + 0, nullptr, yield[ec]); EXPECT_FALSE(ec); + EXPECT_LT(0, ver); EXPECT_EQ("hello", bl.to_str()); }; boost::asio::spawn(service, success_cr, rethrow); @@ -269,10 +286,12 @@ TEST_F(AsioRados, AsyncReadOperationYield) auto failure_cr = [&] (boost::asio::yield_context yield) { librados::ObjectReadOperation op; op.read(0, 0, nullptr, nullptr); - boost::system::error_code ec; - auto bl = librados::async_operate(service, io, "noexist", &op, 0, nullptr, - yield[ec]); + error_code ec; + auto [ver, bl] = librados::async_operate(service, io, "noexist", &op, + 0, nullptr, yield[ec]); EXPECT_EQ(boost::system::errc::no_such_file_or_directory, ec); + EXPECT_EQ(0, ver); + EXPECT_EQ(0, bl.length()); }; boost::asio::spawn(service, failure_cr, rethrow); @@ -289,16 +308,18 @@ TEST_F(AsioRados, AsyncWriteOperationCallback) { librados::ObjectWriteOperation op; op.write_full(bl); - auto success_cb = [&] (boost::system::error_code ec) { + auto success_cb = [&] (error_code ec, version_t ver) { EXPECT_FALSE(ec); + EXPECT_LT(0, ver); }; librados::async_operate(service, io, "exist", &op, 0, nullptr, success_cb); } { librados::ObjectWriteOperation op; op.write_full(bl); - auto failure_cb = [&] (boost::system::error_code ec) { + auto failure_cb = [&] (error_code ec, version_t ver) { EXPECT_EQ(boost::system::errc::read_only_file_system, ec); + EXPECT_EQ(0, ver); }; librados::async_operate(service, snapio, "exist", &op, 0, nullptr, failure_cb); } @@ -312,14 +333,14 @@ TEST_F(AsioRados, AsyncWriteOperationFuture) bufferlist bl; bl.append("hello"); - std::future<void> f1; + std::future<version_t> f1; { librados::ObjectWriteOperation op; op.write_full(bl); f1 = librados::async_operate(service, io, "exist", &op, 0, nullptr, boost::asio::use_future); } - std::future<void> f2; + std::future<version_t> f2; { librados::ObjectWriteOperation op; op.write_full(bl); @@ -328,7 +349,7 @@ TEST_F(AsioRados, AsyncWriteOperationFuture) } service.run(); - EXPECT_NO_THROW(f1.get()); + EXPECT_LT(0, f1.get()); EXPECT_THROW(f2.get(), boost::system::system_error); } @@ -342,18 +363,22 @@ TEST_F(AsioRados, AsyncWriteOperationYield) auto success_cr = [&] (boost::asio::yield_context yield) { librados::ObjectWriteOperation op; op.write_full(bl); - boost::system::error_code ec; - librados::async_operate(service, io, "exist", &op, 0, nullptr, yield[ec]); + error_code ec; + auto ver = librados::async_operate(service, io, "exist", &op, + 0, nullptr, yield[ec]); EXPECT_FALSE(ec); + EXPECT_LT(0, ver); }; boost::asio::spawn(service, success_cr, rethrow); auto failure_cr = [&] (boost::asio::yield_context yield) { librados::ObjectWriteOperation op; op.write_full(bl); - boost::system::error_code ec; - librados::async_operate(service, snapio, "exist", &op, 0, nullptr, yield[ec]); + error_code ec; + auto ver = librados::async_operate(service, snapio, "exist", &op, + 0, nullptr, yield[ec]); EXPECT_EQ(boost::system::errc::read_only_file_system, ec); + EXPECT_EQ(0, ver); }; boost::asio::spawn(service, failure_cr, rethrow); |