From f4cee545faddfb57250763aa86cf136434c9e853 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Mon, 11 May 2026 21:46:27 -0400 Subject: [PATCH] Update test_tray.cpp --- tests/unit/test_tray.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/unit/test_tray.cpp b/tests/unit/test_tray.cpp index 4a91562..103896e 100644 --- a/tests/unit/test_tray.cpp +++ b/tests/unit/test_tray.cpp @@ -3,6 +3,7 @@ // standard includes #include +#include #include #include #include @@ -97,8 +98,8 @@ protected: // NOSONAR(cpp:S3656) - TEST_F generates subclasses that need access trayRunning = false; } - // Dismisses the open menu and exits the tray event loop from a background thread. - void closeMenuAndExit() { + // Dismisses the open menu from a background thread. + void closeMenu() { #if defined(TRAY_WINAPI) PostMessage(tray_get_hwnd(), WM_CANCELMODE, 0, 0); std::this_thread::sleep_for(std::chrono::milliseconds(100)); @@ -111,18 +112,22 @@ protected: // NOSONAR(cpp:S3656) - TEST_F generates subclasses that need access CFRelease(event2); std::this_thread::sleep_for(std::chrono::milliseconds(100)); #endif - tray_exit(); } // Capture a screenshot while the tray menu is open, then dismiss and exit. void captureMenuStateAndExit(const char *screenshotName) { - std::thread capture_thread([this, screenshotName]() { // NOSONAR(cpp:S6168) - std::jthread is unavailable on AppleClang 17/libc++ used in CI + std::atomic_bool exitRequested {false}; + std::thread capture_thread([this, screenshotName, &exitRequested]() { // NOSONAR(cpp:S6168) - std::jthread is unavailable on AppleClang 17/libc++ used in CI EXPECT_TRUE(captureScreenshot(screenshotName)); - closeMenuAndExit(); + closeMenu(); + exitRequested.store(true, std::memory_order_release); }); tray_show_menu(); while (tray_loop(0) == 0) { + if (exitRequested.load(std::memory_order_acquire)) { + tray_exit(); + } std::this_thread::sleep_for(std::chrono::milliseconds(10)); } capture_thread.join();