Skip to content
Permalink
Browse files

[test] Add ParentDependsOnSubTask subtask test case

  • Loading branch information
elpaso authored and nyalldawson committed Aug 14, 2018
1 parent ba4fb65 commit 4ad0bbb1d11a63ecef94ba5b8764e6617b9f7662
Showing with 31 additions and 0 deletions.
  1. +31 −0 tests/src/python/test_qgstaskmanager.py
@@ -17,6 +17,7 @@
from qgis.core import QgsTask, QgsApplication

from qgis.PyQt.QtCore import QCoreApplication
from qgis.PyQt.QtTest import QSignalSpy

from qgis.testing import start_app, unittest
from time import sleep
@@ -261,6 +262,36 @@ def finished_multiple_value_result(e, results):
self.assertEqual(result_value, 5)
self.assertEqual(result_statement, 'whoo')

def testTaskFromFunctionWithSubTaskCompletedIsCalledOnce(self):
""" test that when a parent task has subtasks it does emit taskCompleted only once"""

self.finished = 0
self.completed = 0

def _on_finished():
self.finished += 1

def _on_completed():
self.completed += 1

task = QgsTask.fromFunction('test task', run_no_result, on_finished=_on_finished)
task.taskCompleted.connect(_on_completed)
spy = QSignalSpy(task.taskCompleted)
sub_task_1 = QgsTask.fromFunction('test subtask 1', run_no_result, on_finished=_on_finished)
sub_task_2 = QgsTask.fromFunction('test subtask 2', run_no_result, on_finished=_on_finished)
task.addSubTask(sub_task_1, [], QgsTask.ParentDependsOnSubTask)
task.addSubTask(sub_task_2, [], QgsTask.ParentDependsOnSubTask)

QgsApplication.taskManager().addTask(task)
while task.status() not in [QgsTask.Complete, QgsTask.Terminated]:
pass
while QgsApplication.taskManager().countActiveTasks() > 0:
QCoreApplication.processEvents()

self.assertEqual(self.completed, 1)
self.assertEqual(self.finished, 3)
self.assertEqual(len(spy), 1)


if __name__ == '__main__':
unittest.main()

0 comments on commit 4ad0bbb

Please sign in to comment.
You can’t perform that action at this time.