]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
test: librados startup/shutdown racer test
authorJeff Layton <jlayton@redhat.com>
Tue, 24 Sep 2019 14:40:00 +0000 (10:40 -0400)
committerJeff Layton <jlayton@redhat.com>
Wed, 25 Sep 2019 12:12:06 +0000 (08:12 -0400)
Spawn a bunch of threads, have them do a cluster_connect and immediately
shut the connection down again. Do this in a loop and allow the thread
to exit. Join all of the threads.

This helps ferret out places where state that is global to the program
is inadequately protected.

Test-for: https://tracker.ceph.com/issues/42026
Signed-off-by: Jeff Layton <jlayton@redhat.com>
src/test/librados/misc.cc

index 5f7fdd889f5a5accc05c1663129ea83225384ce2..0c351db2d264502abdf662ff19447e478820e0e8 100644 (file)
@@ -16,6 +16,8 @@
 #include "test/librados/test.h"
 #include "test/librados/TestCase.h"
 #include "gtest/gtest.h"
+#include <sys/time.h>
+#include <sys/resource.h>
 
 #include <errno.h>
 #include <map>
@@ -308,3 +310,36 @@ TEST_F(LibRadosMisc, MinCompatClient) {
   ASSERT_LE(-1, require_min_compat_client);
   ASSERT_GT(CEPH_RELEASE_MAX, require_min_compat_client);
 }
+
+static void shutdown_racer_func()
+{
+  const int niter = 32;
+  rados_t rad;
+  int i;
+
+  for (i = 0; i < niter; ++i) {
+    ASSERT_EQ("", connect_cluster(&rad));
+    rados_shutdown(rad);
+  }
+}
+
+// See trackers #20988 and #42026
+TEST_F(LibRadosMisc, ShutdownRace)
+{
+  const int nthreads = 128;
+  std::thread threads[nthreads];
+
+  // Need a bunch of fd's for this test
+  struct rlimit rold, rnew;
+  ASSERT_EQ(getrlimit(RLIMIT_NOFILE, &rold), 0);
+  rnew = rold;
+  rnew.rlim_cur = rnew.rlim_max;
+  ASSERT_EQ(setrlimit(RLIMIT_NOFILE, &rnew), 0);
+
+  for (int i = 0; i < nthreads; ++i)
+    threads[i] = std::thread(shutdown_racer_func);
+
+  for (int i = 0; i < nthreads; ++i)
+    threads[i].join();
+  ASSERT_EQ(setrlimit(RLIMIT_NOFILE, &rold), 0);
+}