aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-11-29 16:23:26 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-11-29 23:34:03 +0000
commit1f3b9b498737f18fa65dc009706be2e4bd5379d1 (patch)
treeca5c975e0adf2e4e782c4eade19cbfce17704864
parent4d25dc4b4711eef3a12a23fb43f5d8ff91902e0b (diff)
Prospective fix for stabilizing qthread_test.py
Test both signals started/finished() in one test function and have QThread.finished() call CoreApplication.quit() as well. This avoids waiting seconds. Change-Id: Ifa85db36f0b2e52baaf135b9ca7e63fbfc2ef7fd Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> (cherry picked from commit f39648ddf900c6845c1ad54187ead34ac41cd354) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/pyside6/tests/QtCore/qthread_test.py55
1 files changed, 23 insertions, 32 deletions
diff --git a/sources/pyside6/tests/QtCore/qthread_test.py b/sources/pyside6/tests/QtCore/qthread_test.py
index 13c92b6f7..77e7393ba 100644
--- a/sources/pyside6/tests/QtCore/qthread_test.py
+++ b/sources/pyside6/tests/QtCore/qthread_test.py
@@ -39,13 +39,11 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import QThread, QCoreApplication, QObject, SIGNAL, QMutex, QTimer
+from PySide6.QtCore import QThread, QCoreApplication, QObject, QTimer, Slot
from PySide6.QtCore import QEventLoop
from helper.usesqcoreapplication import UsesQCoreApplication
-mutex = QMutex()
-
class Dummy(QThread):
'''Dummy thread'''
@@ -56,20 +54,17 @@ class Dummy(QThread):
def run(self):
# Start-quit sequence
self.qobj = QObject()
- mutex.lock()
self.called = True
- mutex.unlock()
class QThreadSimpleCase(UsesQCoreApplication):
def setUp(self):
UsesQCoreApplication.setUp(self)
+ self._started_called = False
+ self._finished_called = False
self.called = False
- def tearDown(self):
- UsesQCoreApplication.tearDown(self)
-
def testThread(self):
# Basic QThread test
obj = Dummy()
@@ -78,41 +73,37 @@ class QThreadSimpleCase(UsesQCoreApplication):
self.assertTrue(obj.called)
- def cb(self, *args):
- self.called = True
- # self.exit_app_cb()
-
+ @Slot()
def abort_application(self):
if self._thread.isRunning():
+ print("Warning: terminating thread", file=sys.stderr)
self._thread.terminate()
self.app.quit()
- def testSignalFinished(self):
- # QThread.finished() (signal)
- obj = Dummy()
- obj.finished.connect(self.cb)
- mutex.lock()
- obj.start()
- mutex.unlock()
+ @Slot()
+ def finished(self):
+ self._finished_called = True
- self._thread = obj
- QTimer.singleShot(1000, self.abort_application)
- self.app.exec()
-
- self.assertTrue(self.called)
+ @Slot()
+ def started(self):
+ self._started_called = True
- def testSignalStarted(self):
- # QThread.started() (signal)
- obj = Dummy()
- obj.started.connect(self.cb)
- obj.start()
+ def testSignals(self):
+ # QThread.finished() (signal)
+ self._thread = Dummy()
+ self._thread.started.connect(self.started)
+ self._thread.finished.connect(self.finished)
+ self._thread.finished.connect(self.app.quit)
- self._thread = obj
+ QTimer.singleShot(50, self._thread.start)
QTimer.singleShot(1000, self.abort_application)
+
self.app.exec()
+ if self._thread.isRunning():
+ self._thread.wait(100)
- self.assertEqual(obj.qobj.thread(), obj) # test QObject.thread() method
- self.assertTrue(self.called)
+ self.assertTrue(self._started_called)
+ self.assertTrue(self._finished_called)
if __name__ == '__main__':