From eac43fd1251180c218568d3aac1067be5399774c Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Sat, 4 Aug 2018 08:47:12 +0200 Subject: [PATCH] Add concurrency/nesting test for all providers --- tests/src/python/providertestbase.py | 23 +++++++++++++++++++ tests/src/python/test_provider_postgres.py | 26 ---------------------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/tests/src/python/providertestbase.py b/tests/src/python/providertestbase.py index f455986049cf..48ed053d4e03 100644 --- a/tests/src/python/providertestbase.py +++ b/tests/src/python/providertestbase.py @@ -17,6 +17,7 @@ __revision__ = '$Format:%H$' from qgis.core import ( + QgsApplication, QgsRectangle, QgsFeatureRequest, QgsFeature, @@ -886,3 +887,25 @@ def testStringComparison(self): self.assertEqual(count, 5) self.assertFalse(iterator.compileFailed()) self.disableCompiler() + + def testConcurrency(self): + """ + The connection pool has a maximum of 4 connections defined (+2 spare connections) + Make sure that if we exhaust those 4 connections and force another connection + it is actually using the spare connections and does not freeze. + This situation normally happens when (at least) 4 rendering threads are active + in parallel and one requires an expression to be evaluated. + """ + # Acquire the maximum amount of concurrent connections + iterators = list() + for i in range(QgsApplication.instance().maxConcurrentConnectionsPerPool()): + iterators.append(self.vl.getFeatures()) + + # Run an expression that will also do a request and should use a spare + # connection. It just should not deadlock here. + + feat = next(it) + context = QgsExpressionContext() + context.setFeature(feat) + exp = QgsExpression('get_feature(\'{layer}\', \'pk\', 5)'.format(layer=self.vl.id())) + exp.evaluate(context) diff --git a/tests/src/python/test_provider_postgres.py b/tests/src/python/test_provider_postgres.py index cd9c83fbb883..4e63f22c2a5f 100644 --- a/tests/src/python/test_provider_postgres.py +++ b/tests/src/python/test_provider_postgres.py @@ -1143,32 +1143,6 @@ def testCurveToMultipolygon(self): self.assertEqual(g.childCount(), 1) self.assertTrue(g.childGeometry(0).vertexCount() > 3) - def testConcurrency(self): - """ - The connection pool has a maximum of 4 connections defined (+2 spare connections) - Make sure that if we exhaust those 4 connections and force another connection - it is actually using the spare connections and does not freeze. - This situation normally happens when (at least) 4 rendering threads are active - in parallel and one requires an expression to be evaluated. - """ - vl = QgsVectorLayer('{conn} srid=4326 table="qgis_test".{table} (geom) sql='.format(conn=self.dbconn, table='someData'), "testgeom", "postgres") - self.assertTrue(vl.isValid()) - QgsProject.instance().addMapLayer(vl) - - # Acquire the maximum amount of concurrent connections - iterators = list() - for i in range(QgsApplication.instance().maxConcurrentConnectionsPerPool()): - iterators.append(vl.getFeatures()) - - # Run an expression that will also do a request and should use a spare - # connection. It just should not deadlock here. - - feat = next(it) - context = QgsExpressionContext() - context.setFeature(feat) - exp = QgsExpression('get_feature(\'{layer}\', \'pk\', 5)'.format(layer=vl.id())) - exp.evaluate(context) - class TestPyQgsPostgresProviderCompoundKey(unittest.TestCase, ProviderTestCase):