From 6cf49ba1ebdc7f5dd0f1aa7690906d8e38c70d14 Mon Sep 17 00:00:00 2001 From: sdong Date: Wed, 14 Dec 2022 12:06:24 -0800 Subject: [PATCH] ~SleepingBackgroundTask() to wake up the sleeping task (#11036) Summary: Right now, in unit tests, when background tests are sleeping using SleepingBackgroundTask, and the test exits with test assertion failure, the process will hang and it might prevent us to see the test failure message in CI runs. Try to wake up the thread so that the test can exit correctly. Pull Request resolved: https://github.com/facebook/rocksdb/pull/11036 Test Plan: Watch CI succeeds Reviewed By: riversand963 Differential Revision: D42020489 fbshipit-source-id: 5b8441b18d5f67bbb3ade59a1225a8d3c860c2eb --- test_util/testutil.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test_util/testutil.h b/test_util/testutil.h index 1f43156ab36..c2289dd819f 100644 --- a/test_util/testutil.h +++ b/test_util/testutil.h @@ -363,6 +363,16 @@ class SleepingBackgroundTask { done_with_sleep_(false), sleeping_(false) {} + ~SleepingBackgroundTask() { + MutexLock l(&mutex_); + should_sleep_ = false; + while (sleeping_) { + assert(!should_sleep_); + bg_cv_.SignalAll(); + bg_cv_.Wait(); + } + } + bool IsSleeping() { MutexLock l(&mutex_); return sleeping_;