Skip to content

Commit ec4a327

Browse files
committedAug 8, 2018
Make nested iterator request test solid for max conn count changes
1 parent 955323f commit ec4a327

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
 

‎tests/src/python/test_provider_postgres.py

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

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

11451171
class TestPyQgsPostgresProviderCompoundKey(unittest.TestCase, ProviderTestCase):
11461172

0 commit comments

Comments
 (0)
Please sign in to comment.