Skip to content

Commit

Permalink
~SleepingBackgroundTask() to wake up the sleeping task (#11036)
Browse files Browse the repository at this point in the history
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: #11036

Test Plan: Watch CI succeeds

Reviewed By: riversand963

Differential Revision: D42020489

fbshipit-source-id: 5b8441b18d5f67bbb3ade59a1225a8d3c860c2eb
  • Loading branch information
siying authored and ajkr committed Feb 1, 2023
1 parent a63980e commit 6cf49ba
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test_util/testutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down

0 comments on commit 6cf49ba

Please sign in to comment.