@@ -139,41 +139,39 @@ def __init__(self, message, cmd):
139
139
def __str__ (self ):
140
140
return '\n ERROR: {0}\n CMD: {1}' .format (repr (self .message ), self .cmd )
141
141
142
- if not hasattr (testgres .PostgresNode , "slow_start" ):
143
- # Monkey-Patch testgres.PostgresNode - add slow_start method
144
- def slow_start (self , replica = False ):
145
142
146
- # wait for https://github.com/postgrespro/testgres/pull/50
147
- # self.start()
148
- # self.poll_query_until(
149
- # "postgres",
150
- # "SELECT not pg_is_in_recovery()",
151
- # suppress={testgres.NodeConnection})
152
- if replica :
153
- query = 'SELECT pg_is_in_recovery()'
154
- else :
155
- query = 'SELECT not pg_is_in_recovery()'
143
+ def _slow_start (self , replica = False ):
144
+
145
+ # wait for https://github.com/postgrespro/testgres/pull/50
146
+ # self.start()
147
+ # self.poll_query_until(
148
+ # "postgres",
149
+ # "SELECT not pg_is_in_recovery()",
150
+ # suppress={testgres.NodeConnection})
151
+ if replica :
152
+ query = 'SELECT pg_is_in_recovery()'
153
+ else :
154
+ query = 'SELECT not pg_is_in_recovery()'
155
+
156
+ self .start ()
157
+ while True :
158
+ try :
159
+ output = self .safe_psql ('template1' , query ).decode ("utf-8" ).rstrip ()
156
160
157
- self .start ()
158
- while True :
159
- try :
160
- output = self .safe_psql ('template1' , query ).decode ("utf-8" ).rstrip ()
161
-
162
- if output == 't' :
163
- break
164
-
165
- except testgres .QueryException as e :
166
- if 'database system is starting up' in e .message :
167
- pass
168
- elif 'FATAL: the database system is not accepting connections' in e .message :
169
- pass
170
- elif replica and 'Hot standby mode is disabled' in e .message :
171
- raise e
172
- else :
173
- raise e
161
+ if output == 't' :
162
+ break
163
+
164
+ except testgres .QueryException as e :
165
+ if 'database system is starting up' in e .message :
166
+ pass
167
+ elif 'FATAL: the database system is not accepting connections' in e .message :
168
+ pass
169
+ elif replica and 'Hot standby mode is disabled' in e .message :
170
+ raise e
171
+ else :
172
+ raise e
174
173
175
- sleep (0.5 )
176
- testgres .PostgresNode .slow_start = slow_start
174
+ sleep (0.5 )
177
175
178
176
179
177
def is_test_result_ok (test_case ):
@@ -199,6 +197,29 @@ def is_test_result_ok(test_case):
199
197
return ok
200
198
201
199
200
+ class PostgresNodeExtended (testgres .PostgresNode ):
201
+
202
+ def __init__ (self , base_dir , * args , ** kwargs ):
203
+ super (PostgresNodeExtended , self ).__init__ (name = 'test' , base_dir = base_dir , * args , ** kwargs )
204
+ self .should_rm_dirs = True
205
+ self .is_started = False
206
+
207
+ def slow_start (self , replica = False ):
208
+ _slow_start (self , replica = replica )
209
+
210
+ def start (self , * args , ** kwargs ):
211
+ if not self .is_started :
212
+ super (PostgresNodeExtended , self ).start (* args , ** kwargs )
213
+ self .is_started = True
214
+ return self
215
+
216
+ def stop (self , * args , ** kwargs ):
217
+ if self .is_started :
218
+ result = super (PostgresNodeExtended , self ).stop (* args , ** kwargs )
219
+ self .is_started = False
220
+ return result
221
+
222
+
202
223
class ProbackupTest (object ):
203
224
# Class attributes
204
225
enterprise = is_enterprise ()
@@ -420,8 +441,10 @@ def make_empty_node(
420
441
shutil .rmtree (real_base_dir , ignore_errors = True )
421
442
os .makedirs (real_base_dir )
422
443
423
- node = testgres .get_new_node ('test' , base_dir = real_base_dir )
424
- node .should_rm_dirs = True
444
+ node = PostgresNodeExtended (base_dir = real_base_dir )
445
+
446
+ self .nodes_to_cleanup .append (node )
447
+
425
448
return node
426
449
427
450
def make_simple_node (
@@ -485,8 +508,6 @@ def make_simple_node(
485
508
self .set_auto_conf (
486
509
node , {}, 'postgresql.conf' , ['wal_keep_segments' ])
487
510
488
- self .nodes_to_cleanup .append (node )
489
-
490
511
return node
491
512
492
513
def simple_bootstrap (self , node , role ) -> None :
0 commit comments