From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/test/librados/service_cxx.cc | 104 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/test/librados/service_cxx.cc (limited to 'src/test/librados/service_cxx.cc') diff --git a/src/test/librados/service_cxx.cc b/src/test/librados/service_cxx.cc new file mode 100644 index 000000000..40869f0f8 --- /dev/null +++ b/src/test/librados/service_cxx.cc @@ -0,0 +1,104 @@ +#include +#include +#include +#include "gtest/gtest.h" + +#include "include/rados/librados.hpp" +#include "include/stringify.h" +#include "common/config_proxy.h" +#include "test/librados/test_cxx.h" +#include "test/librados/testcase_cxx.h" +#include "test/unit.cc" + +using namespace librados; + +TEST(LibRadosServicePP, RegisterEarly) { + Rados cluster; + cluster.init("admin"); + ASSERT_EQ(0, cluster.conf_read_file(NULL)); + cluster.conf_parse_env(NULL); + string name = string("pid") + stringify(getpid()); + ASSERT_EQ(0, cluster.service_daemon_register( + "laundry", name, {{"foo", "bar"}, {"this", "that"}})); + ASSERT_EQ(-EEXIST, cluster.service_daemon_register( + "laundry", name, {{"foo", "bar"}, {"this", "that"}})); + ASSERT_EQ(0, cluster.connect()); + sleep(5); + cluster.shutdown(); +} + +TEST(LibRadosServicePP, RegisterLate) { + Rados cluster; + cluster.init("admin"); + ASSERT_EQ(0, cluster.conf_read_file(NULL)); + cluster.conf_parse_env(NULL); + ASSERT_EQ("", connect_cluster_pp(cluster)); + string name = string("pid") + stringify(getpid()); + ASSERT_EQ(0, cluster.service_daemon_register( + "laundry", name, {{"foo", "bar"}, {"this", "that"}})); +} + +TEST(LibRadosServicePP, Status) { + Rados cluster; + cluster.init("admin"); + ASSERT_EQ(0, cluster.conf_read_file(NULL)); + cluster.conf_parse_env(NULL); + string name = string("pid") + stringify(getpid()); + ASSERT_EQ(-ENOTCONN, cluster.service_daemon_update_status( + {{"testing", "starting"}})); + ASSERT_EQ(0, cluster.connect()); + ASSERT_EQ(0, cluster.service_daemon_register( + "laundry", name, {{"foo", "bar"}, {"this", "that"}})); + for (int i=0; i<20; ++i) { + ASSERT_EQ(0, cluster.service_daemon_update_status({ + {"testing", "running"}, + {"count", stringify(i)} + })); + sleep(1); + } + cluster.shutdown(); +} + +TEST(LibRadosServicePP, Close) { + int tries = 20; + string name = string("close-test-pid") + stringify(getpid()); + int i; + for (i = 0; i < tries; ++i) { + cout << "attempt " << i << " of " << tries << std::endl; + { + Rados cluster; + cluster.init("admin"); + ASSERT_EQ(0, cluster.conf_read_file(NULL)); + cluster.conf_parse_env(NULL); + ASSERT_EQ(0, cluster.connect()); + ASSERT_EQ(0, cluster.service_daemon_register( + "laundry", name, {{"foo", "bar"}, {"this", "that"}})); + sleep(3); // let it register + cluster.shutdown(); + } + // mgr updates servicemap every tick + //sleep(g_conf().get_val("mgr_tick_period")); + std::this_thread::sleep_for(g_conf().get_val( + "mgr_tick_period")); + // make sure we are deregistered + { + Rados cluster; + cluster.init("admin"); + ASSERT_EQ(0, cluster.conf_read_file(NULL)); + cluster.conf_parse_env(NULL); + ASSERT_EQ(0, cluster.connect()); + bufferlist inbl, outbl; + ASSERT_EQ(0, cluster.mon_command("{\"prefix\": \"service dump\"}", + inbl, &outbl, NULL)); + string s = outbl.to_str(); + cluster.shutdown(); + + if (s.find(name) != string::npos) { + cout << " failed to deregister:\n" << s << std::endl; + } else { + break; + } + } + } + ASSERT_LT(i, tries); +} -- cgit v1.2.3