summaryrefslogtreecommitdiff
path: root/src/testlib/qtesteventloop.h
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/testlib/qtesteventloop.h
parent2f7d4f478e98bd2babe33795ac367fe6cf8a86f7 (diff)
downloadqtbase-115f828ae406d2805869fccda9269209af646a84.tar.gz
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/testlib/qtesteventloop.h')
-rw-r--r--src/testlib/qtesteventloop.h10
1 files changed, 6 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;