ceftests: Avoid shutdown hang due to leaked TestHandlers

This commit is contained in:
Marshall Greenblatt
2024-01-26 12:58:17 -05:00
parent 132ac7a180
commit 2a86a02bdd
2 changed files with 14 additions and 4 deletions

View File

@@ -77,7 +77,17 @@ void RunTestsOnTestThread() {
CefTestSuite::GetInstance()->Run();
// Wait for all TestHandlers to be destroyed.
while (TestHandler::HasTestHandler()) {
size_t loop_count = 0;
while (true) {
const size_t handler_count = TestHandler::GetTestHandlerCount();
if (handler_count == 0) {
break;
}
if (++loop_count == 20) {
LOG(ERROR) << "Terminating with " << handler_count
<< " leaked TestHandler objects";
break;
}
sleep(100);
}

View File

@@ -211,9 +211,9 @@ class TestHandler : public CefClient,
void OnWindowCreated(int browser_id);
void OnWindowDestroyed(int browser_id);
// Returns true if a TestHandler currently exists.
static bool HasTestHandler() {
return test_handler_count_.load(std::memory_order_relaxed) > 0U;
// Returns the count of TestHandlers the currently exist.
static size_t GetTestHandlerCount() {
return test_handler_count_.load(std::memory_order_relaxed);
}
std::string debug_string_prefix() const { return debug_string_prefix_; }