Skip to content

Commit 7033b54

Browse files
committed
Add test for nested connection pool acquire freeze
1 parent 62a56b1 commit 7033b54

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

tests/src/python/test_provider_postgres.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
QgsCoordinateReferenceSystem,
4545
QgsProject,
4646
QgsWkbTypes,
47-
QgsGeometry
47+
QgsGeometry,
48+
QgsExpression,
49+
QgsExpressionContext
4850
)
4951
from qgis.gui import QgsGui, QgsAttributeForm
5052
from qgis.PyQt.QtCore import QDate, QTime, QDateTime, QVariant, QDir, QObject
@@ -1141,6 +1143,27 @@ def testCurveToMultipolygon(self):
11411143
self.assertEqual(g.childCount(), 1)
11421144
self.assertTrue(g.childGeometry(0).vertexCount() > 3)
11431145

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+
it = vl.getFeatures()
1157+
it2 = vl.getFeatures()
1158+
it3 = vl.getFeatures()
1159+
it4 = vl.getFeatures()
1160+
QgsProject.instance().addMapLayer(vl)
1161+
feat = next(it)
1162+
context = QgsExpressionContext()
1163+
context.setFeature(feat)
1164+
exp = QgsExpression('get_feature(\'{layer}\', \'pk\', 5)'.format(layer=vl.id()))
1165+
exp.evaluate(context)
1166+
11441167

11451168
class TestPyQgsPostgresProviderCompoundKey(unittest.TestCase, ProviderTestCase):
11461169

0 commit comments

Comments
 (0)