summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-07-13 14:11:01 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2021-08-05 01:07:41 +0200
commit115f828ae406d2805869fccda9269209af646a84 (patch)
tree65c0392b28fca4ea7892e7f7927c484439d59fd7 /src
parent2f7d4f478e98bd2babe33795ac367fe6cf8a86f7 (diff)
QTestEventLoop: stop when the test fails
It makes no sense for the event loop of a test to keep running after a test has failed. This lets test code simply use the usual testlib macros to compare and verify values in asynchronous tests that would otherwise need to hand-test values and send a signal on failure (that the main test can connect to an event-loops quit() or equivalent). For example, QLocalSocket's benchmark simply uses the usual macros, without doing anything to stop its event loop if they fail, with the sad result that, when a test fails, it does so repeatedly and then times out, causing the test program to be killed without running later tests. With this change, that test code (once converted to use QTestEventLoop) is able to exit gracefully on the first failure. [ChangeLog][QtTest][QTestEventLoop] The QTestEventLoop new exits its event loop as soon as the test is known to be failing. Task-number: QTBUG-91713 Change-Id: If0d455741668722034906763025dda496d2afbb4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/testlib/qtesteventloop.h10
-rw-r--r--src/testlib/qtestresult.cpp2
2 files changed, 8 insertions, 4 deletions
diff --git a/src/testlib/qtesteventloop.h b/src/testlib/qtesteventloop.h
index d576de4267..10bb4f3f96 100644
--- a/src/testlib/qtesteventloop.h
+++ b/src/testlib/qtesteventloop.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtTest module of the Qt Toolkit.
@@ -41,6 +41,7 @@
#define QTESTEVENTLOOP_H
#include <QtTest/qttestglobal.h>
+#include <QtTest/qtestcase.h>
#include <QtCore/qcoreapplication.h>
#include <QtCore/qeventloop.h>
@@ -93,11 +94,12 @@ private:
inline void QTestEventLoop::enterLoopMSecs(int ms)
{
Q_ASSERT(!loop);
-
- QEventLoop l;
-
_timeout = false;
+ if (QTest::currentTestFailed())
+ return;
+
+ QEventLoop l;
timerId = startTimer(ms);
loop = &l;
diff --git a/src/testlib/qtestresult.cpp b/src/testlib/qtestresult.cpp
index 7498b92024..581e8bc33b 100644
--- a/src/testlib/qtestresult.cpp
+++ b/src/testlib/qtestresult.cpp
@@ -46,6 +46,7 @@
#include <QtTest/qtestdata.h>
#include <QtTest/qtestcase.h>
#include <QtTest/qtestassert.h>
+#include <QtTest/qtesteventloop.h>
#include <stdlib.h>
#include <stdio.h>
@@ -464,6 +465,7 @@ bool QTestResult::compare(bool success, const char *failureMsg,
void QTestResult::addFailure(const char *message, const char *file, int line)
{
clearExpectFail();
+ QTestEventLoop::instance().exitLoop();
if (QTest::blacklistCurrentTest)
QTestLog::addBFail(message, file, line);