From 8252f3168a1bc90add7f7515c549e9eecffa54b7 Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Thu, 14 Sep 2017 09:28:33 -0400 Subject: [PATCH] client: test shutdown race 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 --- src/test/libcephfs/test.cc | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index e492708fb2e31..5e4de0b55e225 100644 --- a/src/test/libcephfs/test.cc +++ b/src/test/libcephfs/test.cc @@ -23,6 +23,8 @@ #include #include #include +#include +#include #ifdef __linux__ #include @@ -30,6 +32,7 @@ #include #include +#include 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); +} -- 2.39.5