]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: test shutdown race 17738/head
authorJeff Layton <jlayton@redhat.com>
Thu, 14 Sep 2017 13:28:33 +0000 (09:28 -0400)
committerJeff Layton <jlayton@redhat.com>
Sat, 16 Sep 2017 12:59:29 +0000 (08:59 -0400)
Spawn threads that bring up a bunch of ceph_mounts with individual
CephContext objects, and then tear them down in parallel.

Tracker: http://tracker.ceph.com/issues/20988
Signed-off-by: Jeff Layton <jlayton@redhat.com>
src/test/libcephfs/test.cc

index e492708fb2e31e464edbc5c15f9a44850486de0c..5e4de0b55e22588b8eb5f7fadc172233783f4560 100644 (file)
@@ -23,6 +23,8 @@
 #include <dirent.h>
 #include <sys/xattr.h>
 #include <sys/uio.h>
+#include <sys/time.h>
+#include <sys/resource.h>
 
 #ifdef __linux__
 #include <limits.h>
@@ -30,6 +32,7 @@
 
 #include <map>
 #include <vector>
+#include <thread>
 
 TEST(LibCephFS, OpenEmptyComponent) {
 
@@ -1858,3 +1861,36 @@ TEST(LibCephFS, OperationsOnRoot)
 
   ceph_shutdown(cmount);
 }
+
+#define NTHREADS 128
+
+static void shutdown_racer_func()
+{
+  struct ceph_mount_info *cmount;
+
+  ASSERT_EQ(ceph_create(&cmount, NULL), 0);
+  ASSERT_EQ(ceph_conf_read_file(cmount, NULL), 0);
+  ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL));
+  ASSERT_EQ(ceph_mount(cmount, "/"), 0);
+  ceph_shutdown(cmount);
+}
+
+// See tracker #20988
+TEST(LibCephFS, ShutdownRace)
+{
+  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);
+}