summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Blechmann <[email protected]>2024-10-29 12:53:53 +0800
committerTim Blechmann <[email protected]>2024-12-02 19:01:20 +0800
commit56106d1bd770c474bc15df47ae6aa64d37ea3d20 (patch)
treeec00dfa63f59e6849f77e6e30b019cec17748ab6
parent182604ae9ce5fac6c1c79bb3f21b5d50e6da7258 (diff)
Testlib: improve messageHandler without loggers
When the messageHandler is called without loggers, we used to simply try to restore the old message handler. This is not ideal and the assertion seems to be wrong. The situation of not having any loggers can occur during teardown, if the message logger is called from a worker thread, while the application thread stops logging (compare QTBUG-129722) In this case, we simply forward the message to the original message handler, which should simply print the message. Pick-to: 6.8 Change-Id: Ic8147f7ab6317f1ceb4f52c79ce298464a94de30 Reviewed-by: Tor Arne Vestbø <[email protected]>
-rw-r--r--src/testlib/qtestlog.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp
index 39178feb2b7..e5781fbeaae 100644
--- a/src/testlib/qtestlog.cpp
+++ b/src/testlib/qtestlog.cpp
@@ -209,9 +209,11 @@ namespace QTest {
static QBasicAtomicInt counter = Q_BASIC_ATOMIC_INITIALIZER(QTest::maxWarnings);
if (!QTestLog::hasLoggers()) {
- // if this goes wrong, something is seriously broken.
- qInstallMessageHandler(oldMessageHandler);
- QTEST_ASSERT(QTestLog::hasLoggers());
+ // the message handler may be called from a worker thread, after the main thread stopped logging.
+ // Forwarding to original message handler to avoid swallowing the message
+ Q_ASSERT(oldMessageHandler);
+ oldMessageHandler(type, context, message);
+ return;
}
if (handleIgnoredMessage(type, message)) {