[TestSignalStackTrace] scope cleanup for test thread Use scope clean-up object to allow the test thread to join if the test fails somewhere in the middle. This helps to avoid TSAN warnings on read/write races in such cases.
Change-Id: Iee425a12fe0101cd9f1ff61d28a8af20a105cbc2 Reviewed-on: http://gerrit.cloudera.org:8080/5171 Reviewed-by: Adar Dembo <[email protected]> Tested-by: Kudu Jenkins Project: http://git-wip-us.apache.org/repos/asf/kudu/repo Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/ade9da71 Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/ade9da71 Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/ade9da71 Branch: refs/heads/master Commit: ade9da7176bb6ab0a29c2c6a7a6abdeb3adee849 Parents: b60508a Author: Alexey Serbin <[email protected]> Authored: Mon Nov 21 17:01:50 2016 -0800 Committer: Alexey Serbin <[email protected]> Committed: Tue Nov 22 02:13:03 2016 +0000 ---------------------------------------------------------------------- src/kudu/util/debug-util-test.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kudu/blob/ade9da71/src/kudu/util/debug-util-test.cc ---------------------------------------------------------------------- diff --git a/src/kudu/util/debug-util-test.cc b/src/kudu/util/debug-util-test.cc index 407bd76..df734ed 100644 --- a/src/kudu/util/debug-util-test.cc +++ b/src/kudu/util/debug-util-test.cc @@ -23,6 +23,7 @@ #include "kudu/gutil/ref_counted.h" #include "kudu/util/countdown_latch.h" #include "kudu/util/debug-util.h" +#include "kudu/util/scoped_cleanup.h" #include "kudu/util/test_util.h" #include "kudu/util/thread.h" @@ -83,6 +84,11 @@ TEST_F(DebugUtilTest, TestSignalStackTrace) { CountDownLatch l(1); scoped_refptr<Thread> t; ASSERT_OK(Thread::Create("test", "test thread", &SleeperThread, &l, &t)); + auto cleanup_thr = MakeScopedCleanup([&]() { + // Allow the thread to finish. + l.CountDown(); + t->Join(); + }); // We have to loop a little bit because it takes a little while for the thread // to start up and actually call our function. @@ -124,10 +130,6 @@ TEST_F(DebugUtilTest, TestSignalStackTrace) { // Re-enable so that other tests pass. ASSERT_OK(SetStackTraceSignal(SIGUSR2)); - - // Allow the thread to finish. - l.CountDown(); - t->Join(); } // Test which dumps all known threads within this process.
