From 10eb5e99d4c72cf10305e6e9af4a9b1bf50900e9 Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Tue, 24 Sep 2019 10:40:00 -0400 Subject: [PATCH] test: librados startup/shutdown racer test 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 (cherry picked from commit 9b6ed03e607fe150c40f977043788efbd5116ddd) --- src/test/librados/misc.cc | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/test/librados/misc.cc b/src/test/librados/misc.cc index 5f7fdd889f5a5..0c351db2d2645 100644 --- a/src/test/librados/misc.cc +++ b/src/test/librados/misc.cc @@ -16,6 +16,8 @@ #include "test/librados/test.h" #include "test/librados/TestCase.h" #include "gtest/gtest.h" +#include +#include #include #include @@ -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); +} -- 2.39.5