]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
test/rgw: add unit test for HTTPManager
authorCasey Bodley <cbodley@redhat.com>
Thu, 16 Jun 2016 23:55:07 +0000 (19:55 -0400)
committerCasey Bodley <cbodley@redhat.com>
Fri, 17 Jun 2016 16:32:27 +0000 (12:32 -0400)
unit test to detect a deadlock in RGWHTTPManager::signal_thread() when
HAVE_CURL_MULTI_WAIT=0

Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/test/Makefile-client.am
src/test/rgw/CMakeLists.txt
src/test/rgw/test_http_manager.cc [new file with mode: 0644]

index 0f9af334862ba28cd679df53518445fcf0ad6be5..4f9ef6c26b3e2b7734306647153fbfac2ff18186 100644 (file)
@@ -718,6 +718,13 @@ ceph_test_rgw_period_history_LDADD = \
 ceph_test_rgw_period_history_CXXFLAGS = $(UNITTEST_CXXFLAGS)
 bin_DEBUGPROGRAMS += ceph_test_rgw_period_history
 
+ceph_test_http_manager_SOURCES = test/rgw/test_http_manager.cc
+ceph_test_http_manager_LDADD = \
+       $(LIBRADOS) $(LIBRGW) $(LIBRGW_DEPS) $(CEPH_GLOBAL) \
+       $(UNITTEST_LDADD) $(CRYPTO_LIBS) -lcurl -lexpat
+ceph_test_http_manager_CXXFLAGS = $(UNITTEST_CXXFLAGS)
+bin_DEBUGPROGRAMS += ceph_test_http_manager
+
 ceph_test_rgw_obj_SOURCES = test/rgw/test_rgw_obj.cc
 ceph_test_rgw_obj_LDADD = \
        $(LIBRADOS) $(LIBRGW) $(LIBRGW_DEPS) $(CEPH_GLOBAL) \
index 05a53b4b4539003fe32f2c7369275fe0b1d8c369..80f5b34ebb18236bc8103ade04244ee851a8459f 100644 (file)
@@ -3,6 +3,11 @@ add_executable(unittest_rgw_period_history EXCLUDE_FROM_ALL test_rgw_period_hist
 add_ceph_unittest(unittest_rgw_period_history ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest_rgw_period_history)
 target_link_libraries(unittest_rgw_period_history rgw_a)
 
+# unitttest_http_manager
+add_executable(unittest_http_manager EXCLUDE_FROM_ALL test_http_manager.cc)
+add_ceph_unittest(unittest_http_manager ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest_http_manager)
+target_link_libraries(unittest_http_manager rgw_a)
+
 # ceph_test_rgw_manifest
 set(test_rgw_manifest_srcs test_rgw_manifest.cc)
 add_executable(ceph_test_rgw_manifest
diff --git a/src/test/rgw/test_http_manager.cc b/src/test/rgw/test_http_manager.cc
new file mode 100644 (file)
index 0000000..abc5853
--- /dev/null
@@ -0,0 +1,59 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2015 Red Hat
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+#include "rgw/rgw_rados.h"
+#include "rgw/rgw_http_client.h"
+#include "global/global_init.h"
+#include "common/ceph_argparse.h"
+#include <curl/curl.h>
+#include <gtest/gtest.h>
+
+TEST(HTTPManager, SignalThread)
+{
+  auto cct = g_ceph_context;
+  RGWHTTPManager http(cct);
+
+  ASSERT_EQ(0, http.set_threaded());
+
+  // default pipe buffer size according to man pipe
+  constexpr size_t max_pipe_buffer_size = 65536;
+  // each signal writes 4 bytes to the pipe
+  constexpr size_t max_pipe_signals = max_pipe_buffer_size / sizeof(uint32_t);
+  // add_request and unregister_request
+  constexpr size_t pipe_signals_per_request = 2;
+  // number of http requests to fill the pipe buffer
+  constexpr size_t max_requests = max_pipe_signals / pipe_signals_per_request;
+
+  // send one extra request to test that we don't deadlock
+  constexpr size_t num_requests = max_requests + 1;
+
+  for (int i = 0; i < num_requests; i++) {
+    RGWHTTPClient client{cct};
+    http.add_request(&client, "PUT", "http://127.0.0.1:80");
+  }
+}
+
+int main(int argc, char** argv)
+{
+  vector<const char*> args;
+  argv_to_vec(argc, (const char **)argv, args);
+
+  global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
+  common_init_finish(g_ceph_context);
+
+  curl_global_init(CURL_GLOBAL_ALL);
+  ::testing::InitGoogleTest(&argc, argv);
+  int r = RUN_ALL_TESTS();
+  curl_global_cleanup();
+  return r;
+}