@@ -237,8 +237,6 @@ def __enter__(self):
237
237
return self
238
238
239
239
def __exit__ (self , type , value , traceback ):
240
- self .free_port ()
241
-
242
240
# NOTE: Ctrl+C does not count!
243
241
got_exception = type is not None and type != KeyboardInterrupt
244
242
@@ -252,6 +250,8 @@ def __exit__(self, type, value, traceback):
252
250
else :
253
251
self ._try_shutdown (attempts )
254
252
253
+ self ._release_resources ()
254
+
255
255
def __repr__ (self ):
256
256
return "{}(name='{}', port={}, base_dir='{}')" .format (
257
257
self .__class__ .__name__ ,
@@ -663,6 +663,9 @@ def _try_shutdown(self, max_attempts, with_force=False):
663
663
ps_output ,
664
664
ps_command )
665
665
666
+ def _release_resources (self ):
667
+ self .free_port ()
668
+
666
669
@staticmethod
667
670
def _throw_bugcheck__unexpected_result_of_ps (result , cmd ):
668
671
assert type (result ) == str # noqa: E721
@@ -1340,7 +1343,7 @@ def free_port(self):
1340
1343
self ._port = None
1341
1344
self ._port_manager .release_port (port )
1342
1345
1343
- def cleanup (self , max_attempts = 3 , full = False ):
1346
+ def cleanup (self , max_attempts = 3 , full = False , release_resources = False ):
1344
1347
"""
1345
1348
Stop node if needed and remove its data/logs directory.
1346
1349
NOTE: take a look at TestgresConfig.node_cleanup_full.
@@ -1363,6 +1366,9 @@ def cleanup(self, max_attempts=3, full=False):
1363
1366
1364
1367
self .os_ops .rmdirs (rm_dir , ignore_errors = False )
1365
1368
1369
+ if release_resources :
1370
+ self ._release_resources ()
1371
+
1366
1372
return self
1367
1373
1368
1374
@method_decorator (positional_args_hack (['dbname' , 'query' ]))
0 commit comments