Skip to content

Commit eac43fd

Browse files
committed
Add concurrency/nesting test for all providers
1 parent 56885e1 commit eac43fd

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

tests/src/python/providertestbase.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
__revision__ = '$Format:%H$'
1818

1919
from qgis.core import (
20+
QgsApplication,
2021
QgsRectangle,
2122
QgsFeatureRequest,
2223
QgsFeature,
@@ -886,3 +887,25 @@ def testStringComparison(self):
886887
self.assertEqual(count, 5)
887888
self.assertFalse(iterator.compileFailed())
888889
self.disableCompiler()
890+
891+
def testConcurrency(self):
892+
"""
893+
The connection pool has a maximum of 4 connections defined (+2 spare connections)
894+
Make sure that if we exhaust those 4 connections and force another connection
895+
it is actually using the spare connections and does not freeze.
896+
This situation normally happens when (at least) 4 rendering threads are active
897+
in parallel and one requires an expression to be evaluated.
898+
"""
899+
# Acquire the maximum amount of concurrent connections
900+
iterators = list()
901+
for i in range(QgsApplication.instance().maxConcurrentConnectionsPerPool()):
902+
iterators.append(self.vl.getFeatures())
903+
904+
# Run an expression that will also do a request and should use a spare
905+
# connection. It just should not deadlock here.
906+
907+
feat = next(it)
908+
context = QgsExpressionContext()
909+
context.setFeature(feat)
910+
exp = QgsExpression('get_feature(\'{layer}\', \'pk\', 5)'.format(layer=self.vl.id()))
911+
exp.evaluate(context)

tests/src/python/test_provider_postgres.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,32 +1143,6 @@ def testCurveToMultipolygon(self):
11431143
self.assertEqual(g.childCount(), 1)
11441144
self.assertTrue(g.childGeometry(0).vertexCount() > 3)
11451145

1146-
def testConcurrency(self):
1147-
"""
1148-
The connection pool has a maximum of 4 connections defined (+2 spare connections)
1149-
Make sure that if we exhaust those 4 connections and force another connection
1150-
it is actually using the spare connections and does not freeze.
1151-
This situation normally happens when (at least) 4 rendering threads are active
1152-
in parallel and one requires an expression to be evaluated.
1153-
"""
1154-
vl = QgsVectorLayer('{conn} srid=4326 table="qgis_test".{table} (geom) sql='.format(conn=self.dbconn, table='someData'), "testgeom", "postgres")
1155-
self.assertTrue(vl.isValid())
1156-
QgsProject.instance().addMapLayer(vl)
1157-
1158-
# Acquire the maximum amount of concurrent connections
1159-
iterators = list()
1160-
for i in range(QgsApplication.instance().maxConcurrentConnectionsPerPool()):
1161-
iterators.append(vl.getFeatures())
1162-
1163-
# Run an expression that will also do a request and should use a spare
1164-
# connection. It just should not deadlock here.
1165-
1166-
feat = next(it)
1167-
context = QgsExpressionContext()
1168-
context.setFeature(feat)
1169-
exp = QgsExpression('get_feature(\'{layer}\', \'pk\', 5)'.format(layer=vl.id()))
1170-
exp.evaluate(context)
1171-
11721146

11731147
class TestPyQgsPostgresProviderCompoundKey(unittest.TestCase, ProviderTestCase):
11741148

0 commit comments

Comments
 (0)