1111import select
1212import psycopg2
1313from time import sleep
14-
14+ import re
1515
1616idx_ptrack = {
1717 't_heap' : {
@@ -156,6 +156,14 @@ def __init__(self, *args, **kwargs):
156156 if 'ARCHIVE_COMPRESSION' in self .test_env :
157157 if self .test_env ['ARCHIVE_COMPRESSION' ] == 'ON' :
158158 self .archive_compress = True
159+ try :
160+ testgres .configure_testgres (
161+ cache_initdb = False ,
162+ cached_initdb_dir = False ,
163+ cache_pg_config = False ,
164+ node_cleanup_full = False )
165+ except :
166+ pass
159167
160168 self .helpers_path = os .path .dirname (os .path .realpath (__file__ ))
161169 self .dir_path = os .path .abspath (
@@ -193,11 +201,16 @@ def make_simple_node(
193201
194202 real_base_dir = os .path .join (self .tmp_path , base_dir )
195203 shutil .rmtree (real_base_dir , ignore_errors = True )
204+ os .makedirs (real_base_dir )
196205
197206 node = testgres .get_new_node ('test' , base_dir = real_base_dir )
198- node .init (initdb_params = initdb_params )
207+ node .should_rm_dirs = True
208+ node .init (
209+ initdb_params = initdb_params , allow_streaming = set_replication )
210+ print (node .data_dir )
199211
200212 # Sane default parameters, not a shit with fsync = off from testgres
213+ node .append_conf ("postgresql.auto.conf" , "max_connections = 100" )
201214 node .append_conf ("postgresql.auto.conf" , "shared_buffers = 10MB" )
202215 node .append_conf ("postgresql.auto.conf" , "fsync = on" )
203216 node .append_conf ("postgresql.auto.conf" , "wal_level = minimal" )
@@ -217,8 +230,13 @@ def make_simple_node(
217230
218231 # Allow replication in pg_hba.conf
219232 if set_replication :
220- node .set_replication_conf ()
221- node .append_conf ("postgresql.auto.conf" , "max_wal_senders = 10" )
233+ node .append_conf (
234+ "pg_hba.conf" ,
235+ "local replication all trust\n " )
236+ node .append_conf (
237+ "postgresql.auto.conf" ,
238+ "max_wal_senders = 10" )
239+
222240 return node
223241
224242 def create_tblspace_in_node (self , node , tblspc_name , tblspc_path = None , cfs = False ):
@@ -235,7 +253,8 @@ def create_tblspace_in_node(self, node, tblspc_name, tblspc_path=None, cfs=False
235253 )
236254
237255 if not tblspc_path :
238- tblspc_path = os .path .join (node .base_dir , '{0}' .format (tblspc_name ))
256+ tblspc_path = os .path .join (
257+ node .base_dir , '{0}' .format (tblspc_name ))
239258 cmd = "CREATE TABLESPACE {0} LOCATION '{1}'" .format (
240259 tblspc_name , tblspc_path )
241260 if cfs :
@@ -272,11 +291,11 @@ def get_md5_per_page_for_fork(self, file, size_in_pages):
272291
273292 size = size_in_pages
274293 for segment_number in range (nsegments ):
275- if size - 131072 > 0 :
294+ if size - 131072 > 0 :
276295 pages_per_segment [segment_number ] = 131072
277296 else :
278297 pages_per_segment [segment_number ] = size
279- size = size - 131072
298+ size = size - 131072
280299
281300 for segment_number in range (nsegments ):
282301 offset = 0
@@ -369,6 +388,7 @@ def check_ptrack_sanity(self, idx_dict):
369388 idx_dict ['ptrack' ][PageNum ])
370389 )
371390 continue
391+
372392 # Ok, all pages in new_pages that do not have
373393 # corresponding page in old_pages are been dealt with.
374394 # We can now safely proceed to comparing old and new pages
@@ -394,7 +414,7 @@ def check_ptrack_sanity(self, idx_dict):
394414 if PageNum == 0 and idx_dict ['type' ] == 'spgist' :
395415 if self .verbose :
396416 print (
397- 'SPGIST is a special snowflake, so don`t'
417+ 'SPGIST is a special snowflake, so don`t '
398418 'fret about losing ptrack for blknum 0'
399419 )
400420 continue
@@ -721,9 +741,9 @@ def set_archiving(
721741 archive_mode = 'on'
722742
723743 node .append_conf (
724- "postgresql.auto.conf" ,
725- "wal_level = archive"
726- )
744+ "postgresql.auto.conf" ,
745+ "wal_level = archive"
746+ )
727747 node .append_conf (
728748 "postgresql.auto.conf" ,
729749 "archive_mode = {0}" .format (archive_mode )
@@ -817,7 +837,15 @@ def get_username(self):
817837 return pwd .getpwuid (os .getuid ())[0 ]
818838
819839 def version_to_num (self , version ):
820- return testgres .version_to_num (version )
840+ if not version :
841+ return 0
842+ parts = version .split ("." )
843+ while len (parts ) < 3 :
844+ parts .append ("0" )
845+ num = 0
846+ for part in parts :
847+ num = num * 100 + int (re .sub ("[^\d]" , "" , part ))
848+ return num
821849
822850 def switch_wal_segment (self , node ):
823851 """ Execute pg_switch_wal/xlog() in given node"""
@@ -829,7 +857,11 @@ def switch_wal_segment(self, node):
829857 node .safe_psql ("postgres" , "select pg_switch_xlog()" )
830858
831859 def get_version (self , node ):
832- return testgres .get_config ()["VERSION_NUM" ]
860+ return self .version_to_num (
861+ testgres .get_pg_config ()["VERSION" ].split (" " )[1 ])
862+
863+ def get_bin_path (self , binary ):
864+ return testgres .get_bin_path (binary )
833865
834866 def del_test_dir (self , module_name , fname ):
835867 """ Del testdir and optimistically try to del module dir"""
@@ -960,7 +992,11 @@ def compare_pgdata(self, original_pgdata, restored_pgdata):
960992 )
961993 for page in restored_pgdata ['files' ][file ]['md5_per_page' ]:
962994 if page not in original_pgdata ['files' ][file ]['md5_per_page' ]:
963- error_message += '\n Extra page {0}\n File: {1}\n ' .format (page , os .path .join (restored_pgdata ['pgdata' ], file ))
995+ error_message += '\n Extra page {0}\n '
996+ 'File: {1}\n ' .format (
997+ page ,
998+ os .path .join (
999+ restored_pgdata ['pgdata' ], file ))
9641000
9651001 else :
9661002 error_message += (
0 commit comments