Skip to content

Commit 9331694

Browse files
committed
test/librados/asio: add test cases for deferred
Signed-off-by: Casey Bodley <[email protected]>
1 parent a546495 commit 9331694

File tree

1 file changed

+179
-0
lines changed

1 file changed

+179
-0
lines changed

src/test/librados/asio.cc

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <boost/asio/bind_cancellation_slot.hpp>
2525
#include <boost/asio/cancellation_signal.hpp>
2626
#include <boost/asio/co_spawn.hpp>
27+
#include <boost/asio/deferred.hpp>
2728
#include <boost/asio/io_context.hpp>
2829
#include <boost/asio/spawn.hpp>
2930
#include <boost/asio/use_future.hpp>
@@ -114,6 +115,36 @@ TEST_F(AsioRados, AsyncReadCallback)
114115
service.run();
115116
}
116117

118+
TEST_F(AsioRados, AsyncReadDeferred)
119+
{
120+
boost::asio::io_context service;
121+
auto ex = service.get_executor();
122+
123+
auto init1 = [&] { // pass local variables that go out of scope
124+
librados::IoCtx ioc = io;
125+
std::string oid = "exist";
126+
return librados::async_read(ex, ioc, oid, 256, 0, boost::asio::deferred);
127+
}();
128+
std::move(init1)([] (error_code ec, version_t ver, bufferlist bl) {
129+
EXPECT_FALSE(ec);
130+
EXPECT_LT(0, ver);
131+
EXPECT_EQ("hello", bl.to_str());
132+
});
133+
134+
auto init2 = [&] {
135+
librados::IoCtx ioc = io;
136+
std::string oid = "noexist";
137+
return librados::async_read(ex, ioc, oid, 256, 0, boost::asio::deferred);
138+
}();
139+
std::move(init2)([] (error_code ec, version_t ver, bufferlist bl) {
140+
EXPECT_EQ(boost::system::errc::no_such_file_or_directory, ec);
141+
EXPECT_EQ(0, ver);
142+
EXPECT_EQ(0, bl.length());
143+
});
144+
145+
service.run();
146+
}
147+
117148
TEST_F(AsioRados, AsyncReadFuture)
118149
{
119150
boost::asio::io_context service;
@@ -237,6 +268,40 @@ TEST_F(AsioRados, AsyncWriteCallback)
237268
service.run();
238269
}
239270

271+
TEST_F(AsioRados, AsyncWriteDeferred)
272+
{
273+
boost::asio::io_context service;
274+
auto ex = service.get_executor();
275+
276+
auto init1 = [&] { // pass local variables that go out of scope
277+
librados::IoCtx ioc = io;
278+
std::string oid = "exist";
279+
bufferlist bl;
280+
bl.append("hello");
281+
return librados::async_write(ex, ioc, oid, bl, bl.length(), 0,
282+
boost::asio::deferred);
283+
}();
284+
std::move(init1)([] (error_code ec, version_t ver) {
285+
EXPECT_FALSE(ec);
286+
EXPECT_LT(0, ver);
287+
});
288+
289+
auto init2 = [&] {
290+
librados::IoCtx ioc = snapio;
291+
std::string oid = "exist";
292+
bufferlist bl;
293+
bl.append("hello");
294+
return librados::async_write(ex, ioc, oid, bl, bl.length(), 0,
295+
boost::asio::deferred);
296+
}();
297+
std::move(init2)([] (error_code ec, version_t ver) {
298+
EXPECT_EQ(boost::system::errc::read_only_file_system, ec);
299+
EXPECT_EQ(0, ver);
300+
});
301+
302+
service.run();
303+
}
304+
240305
TEST_F(AsioRados, AsyncWriteFuture)
241306
{
242307
boost::asio::io_context service;
@@ -360,6 +425,42 @@ TEST_F(AsioRados, AsyncReadOperationCallback)
360425
service.run();
361426
}
362427

428+
TEST_F(AsioRados, AsyncReadOperationDeferred)
429+
{
430+
boost::asio::io_context service;
431+
auto ex = service.get_executor();
432+
433+
auto init1 = [&] { // pass local variables that go out of scope
434+
librados::IoCtx ioc = io;
435+
std::string oid = "exist";
436+
librados::ObjectReadOperation op;
437+
op.read(0, 0, nullptr, nullptr);
438+
return librados::async_operate(ex, ioc, oid, std::move(op),
439+
0, nullptr, boost::asio::deferred);
440+
}();
441+
std::move(init1)([] (error_code ec, version_t ver, bufferlist bl) {
442+
EXPECT_FALSE(ec);
443+
EXPECT_LT(0, ver);
444+
EXPECT_EQ("hello", bl.to_str());
445+
});
446+
447+
auto init2 = [&] {
448+
librados::IoCtx ioc = io;
449+
std::string oid = "noexist";
450+
librados::ObjectReadOperation op;
451+
op.read(0, 0, nullptr, nullptr);
452+
return librados::async_operate(ex, ioc, oid, std::move(op),
453+
0, nullptr, boost::asio::deferred);
454+
}();
455+
std::move(init2)([] (error_code ec, version_t ver, bufferlist bl) {
456+
EXPECT_EQ(boost::system::errc::no_such_file_or_directory, ec);
457+
EXPECT_EQ(0, ver);
458+
EXPECT_EQ(0, bl.length());
459+
});
460+
461+
service.run();
462+
}
463+
363464
TEST_F(AsioRados, AsyncReadOperationFuture)
364465
{
365466
boost::asio::io_context service;
@@ -500,6 +601,44 @@ TEST_F(AsioRados, AsyncWriteOperationCallback)
500601
service.run();
501602
}
502603

604+
TEST_F(AsioRados, AsyncWriteOperationDeferred)
605+
{
606+
boost::asio::io_context service;
607+
auto ex = service.get_executor();
608+
609+
auto init1 = [&] { // pass local variables that go out of scope
610+
librados::IoCtx ioc = io;
611+
std::string oid = "exist";
612+
bufferlist bl;
613+
bl.append("hello");
614+
librados::ObjectWriteOperation op;
615+
op.write_full(bl);
616+
return librados::async_operate(ex, ioc, oid, std::move(op),
617+
0, nullptr, boost::asio::deferred);
618+
}();
619+
std::move(init1)([] (error_code ec, version_t ver) {
620+
EXPECT_FALSE(ec);
621+
EXPECT_LT(0, ver);
622+
});
623+
624+
auto init2 = [&] {
625+
librados::IoCtx ioc = snapio;
626+
std::string oid = "exist";
627+
bufferlist bl;
628+
bl.append("hello");
629+
librados::ObjectWriteOperation op;
630+
op.write_full(bl);
631+
return librados::async_operate(ex, ioc, oid, std::move(op),
632+
0, nullptr, boost::asio::deferred);
633+
}();
634+
std::move(init2)([] (error_code ec, version_t ver) {
635+
EXPECT_EQ(boost::system::errc::read_only_file_system, ec);
636+
EXPECT_EQ(0, ver);
637+
});
638+
639+
service.run();
640+
}
641+
503642
TEST_F(AsioRados, AsyncWriteOperationFuture)
504643
{
505644
boost::asio::io_context service;
@@ -640,6 +779,46 @@ TEST_F(AsioRados, AsyncNotifyCallback)
640779
service.run();
641780
}
642781

782+
TEST_F(AsioRados, AsyncNotifyDeferred)
783+
{
784+
boost::asio::io_context service;
785+
auto ex = service.get_executor();
786+
787+
constexpr uint64_t timeout = 0;
788+
789+
auto init1 = [&] { // pass local variables that go out of scope
790+
librados::IoCtx ioc = io;
791+
std::string oid = "exist";
792+
bufferlist bl;
793+
bl.append("hello");
794+
return librados::async_notify(ex, ioc, oid, bl, timeout,
795+
boost::asio::deferred);
796+
}();
797+
std::move(init1)([&] (error_code ec, version_t ver, bufferlist reply) {
798+
EXPECT_FALSE(ec);
799+
EXPECT_LT(0, ver);
800+
std::vector<librados::notify_ack_t> acks;
801+
std::vector<librados::notify_timeout_t> timeouts;
802+
io.decode_notify_response(reply, &acks, &timeouts);
803+
});
804+
805+
auto init2 = [&] {
806+
librados::IoCtx ioc = io;
807+
std::string oid = "noexist";
808+
bufferlist bl;
809+
bl.append("hello");
810+
return librados::async_notify(ex, ioc, oid, bl, timeout,
811+
boost::asio::deferred);
812+
}();
813+
std::move(init2)([] (error_code ec, version_t ver, bufferlist reply) {
814+
EXPECT_EQ(boost::system::errc::no_such_file_or_directory, ec);
815+
EXPECT_EQ(0, ver);
816+
EXPECT_EQ(0, reply.length());
817+
});
818+
819+
service.run();
820+
}
821+
643822
TEST_F(AsioRados, AsyncNotifyFuture)
644823
{
645824
boost::asio::io_context service;

0 commit comments

Comments
 (0)