From: Jeff Layton Date: Thu, 14 Sep 2017 13:28:33 +0000 (-0400) Subject: client: test shutdown race X-Git-Tag: v13.0.1~856^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F17738%2Fhead;p=ceph.git 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 --- diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index e492708fb2e3..5e4de0b55e22 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); +}