@@ -1141,6 +1141,32 @@ def testCurveToMultipolygon(self):
1141
1141
self .assertEqual (g .childCount (), 1 )
1142
1142
self .assertTrue (g .childGeometry (0 ).vertexCount () > 3 )
1143
1143
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
+
1144
1170
1145
1171
class TestPyQgsPostgresProviderCompoundKey (unittest .TestCase , ProviderTestCase ):
1146
1172
0 commit comments