Skip to content

Commit

Permalink
Fix flaky VirtualLayerTask test
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 15, 2018
1 parent feb20a7 commit 9e351e8
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tests/src/python/test_qgsvirtuallayertask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__':
Expand Down

0 comments on commit 9e351e8

Please sign in to comment.