From: Casey Bodley Date: Thu, 7 Apr 2022 17:10:51 +0000 (-0400) Subject: test/rgw: use mock OpsLogSink instead of OpsLogSocket X-Git-Tag: v18.0.0~1097^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fbdc2a18ca8c66f886662b498179376eddf74aca;p=ceph.git test/rgw: use mock OpsLogSink instead of OpsLogSocket Fixes: https://tracker.ceph.com/issues/55232 Signed-off-by: Casey Bodley --- diff --git a/src/test/rgw/test_rgw_lua.cc b/src/test/rgw/test_rgw_lua.cc index 501144d5a34d..cb1ef64b1f84 100644 --- a/src/test/rgw/test_rgw_lua.cc +++ b/src/test/rgw/test_rgw_lua.cc @@ -593,46 +593,9 @@ TEST(TestRGWLua, NotAllowedInLib) const auto rc = lua::request::execute(nullptr, nullptr, nullptr, &s, "put_obj", script); ASSERT_NE(rc, 0); } -#include -#include - -bool unix_socket_client_ended_ok = false; - -void unix_socket_client(const std::string& path) { - int fd; - // create the socket - if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { - std::cout << "unix socket error: " << errno << std::endl; - return; - } - // set the path - struct sockaddr_un addr; - memset(&addr, 0, sizeof(addr)); - addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, path.c_str(), sizeof(addr.sun_path)-1); - - // let the socket be created by the "rgw" side - std::this_thread::sleep_for(std::chrono::seconds(2)); - if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) { - std::cout << "unix socket connect error: " << errno << std::endl; - return; - } - - char buff[256]; - int rc; - while((rc=read(fd, buff, sizeof(buff))) > 0) { - std::cout << std::string(buff, rc); - unix_socket_client_ended_ok = true; - } -} TEST(TestRGWLua, OpsLog) { - const std::string unix_socket_path = "./aSocket.sock"; - unlink(unix_socket_path.c_str()); - - std::thread unix_socket_thread(unix_socket_client, unix_socket_path); - const std::string script = R"( if Request.Response.HTTPStatusCode == 200 then assert(Request.Response.Message == "Life is great") @@ -644,8 +607,12 @@ TEST(TestRGWLua, OpsLog) auto store = std::unique_ptr(new sal::RadosStore); store->setRados(new RGWRados); - auto olog = std::unique_ptr(new OpsLogSocket(cct, 1024)); - ASSERT_TRUE(olog->init(unix_socket_path)); + + struct MockOpsLogSink : OpsLogSink { + bool logged = false; + int log(req_state*, rgw_log_entry&) override { logged = true; return 0; } + }; + MockOpsLogSink olog; DEFINE_REQ_STATE; s.err.http_ret = 200; @@ -669,16 +636,13 @@ TEST(TestRGWLua, OpsLog) s.auth.identity = std::unique_ptr( new FakeIdentity()); - auto rc = lua::request::execute(store.get(), nullptr, olog.get(), &s, "put_obj", script); + auto rc = lua::request::execute(store.get(), nullptr, &olog, &s, "put_obj", script); EXPECT_EQ(rc, 0); + EXPECT_FALSE(olog.logged); // don't log http_ret=200 s.err.http_ret = 400; - rc = lua::request::execute(store.get(), nullptr, olog.get(), &s, "put_obj", script); + rc = lua::request::execute(store.get(), nullptr, &olog, &s, "put_obj", script); EXPECT_EQ(rc, 0); - - // give the socket client time to read - std::this_thread::sleep_for(std::chrono::seconds(5)); - unix_socket_thread.detach(); // read is stuck there, so we cannot join - EXPECT_TRUE(unix_socket_client_ended_ok); + EXPECT_TRUE(olog.logged); }