Skip to content
Permalink
Browse files

Fix flaky VirtualLayerTask test

  • Loading branch information
nyalldawson committed Mar 15, 2018
1 parent feb20a7 commit 9e351e80fc0531937faddd371febbbcb40b0af8d
Showing with 9 additions and 7 deletions.
  1. +9 −7 tests/src/python/test_qgsvirtuallayertask.py
@@ -35,9 +35,12 @@ def setUp(self):
self.testDataDir = unitTestDataPath()
self.success = False
self.fail = False
self.ids = None
self.task = None

def onSuccess(self):
self.success = True
self.ids = [f.id() for f in self.task.layer().getFeatures()]

def onFail(self):
self.fail = True
@@ -49,23 +52,22 @@ def test(self):

df = QgsVirtualLayerDefinition()
df.setQuery('select * from "françéà"')
task = QgsVirtualLayerTask(df)
self.task = QgsVirtualLayerTask(df)

ids = [f.id() for f in task.layer().getFeatures()]
ids = [f.id() for f in self.task.layer().getFeatures()]
self.assertEqual(len(ids), 0)

task.taskCompleted.connect(self.onSuccess)
task.taskTerminated.connect(self.onFail)
self.task.taskCompleted.connect(self.onSuccess)
self.task.taskTerminated.connect(self.onFail)

QgsApplication.taskManager().addTask(task)
QgsApplication.taskManager().addTask(self.task)
while not self.success and not self.fail:
QCoreApplication.processEvents()

self.assertTrue(self.success)
self.assertFalse(self.fail)

ids = [f.id() for f in task.layer().getFeatures()]
self.assertEqual(len(ids), 4)
self.assertEqual(len(self.ids), 4)


if __name__ == '__main__':

0 comments on commit 9e351e8

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