Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 78503f9

Browse files
committed
Merge remote-tracking branch 'origin/testgres1'
2 parents 304ded6 + 3cfb8e2 commit 78503f9

File tree

6 files changed

+61
-23
lines changed

6 files changed

+61
-23
lines changed

tests/auth_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import signal
99

1010
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
11-
from testgres import ClusterException as StartNodeException
11+
from testgres import StartNodeException
1212

1313
module_name = 'auth_test'
1414
skip_test = False
@@ -123,7 +123,7 @@ def test_right_password(self):
123123
self.fail(e.value)
124124

125125
def test_right_password_and_wrong_pgpass(self):
126-
""" Test case: PGPB_AUTH05 - correct password and incorrect .pgpass"""
126+
""" Test case: PGPB_AUTH05 - correct password and incorrect .pgpass (-W)"""
127127
line = ":".join(['127.0.0.1', str(self.node.port), 'postgres', 'backup', 'wrong_password'])
128128
create_pgpass(self.pgpass_file, line)
129129
try:
@@ -197,7 +197,7 @@ def test_pgpassword_and_wrong_pgpass(self):
197197

198198
def run_pb_with_auth(cmd, password=None, kill=False):
199199
try:
200-
with spawn(" ".join(cmd), timeout=10) as probackup:
200+
with spawn(" ".join(cmd), encoding='utf-8', timeout=10) as probackup:
201201
result = probackup.expect("Password for user .*:", 5)
202202
if kill:
203203
probackup.kill(signal.SIGINT)

tests/helpers/ptrack_helpers.py

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import select
1212
import psycopg2
1313
from time import sleep
14-
14+
import re
1515

1616
idx_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 += (

tests/ptrack.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
44
from datetime import datetime, timedelta
55
import subprocess
6-
from testgres import ClusterException
6+
from testgres import ClusterTestgresException as ClusterException
7+
from testgres import QueryException
78
import shutil
89
import sys
910
import time
@@ -1233,7 +1234,7 @@ def test_create_db(self):
12331234
"\n Output: {0} \n CMD: {1}".format(
12341235
repr(self.output), self.cmd)
12351236
)
1236-
except ClusterException as e:
1237+
except QueryException as e:
12371238
self.assertTrue(
12381239
'FATAL: database "db1" does not exist' in e.message,
12391240
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(

tests/ptrack_recovery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_ptrack_recovery(self):
4040

4141
if self.verbose:
4242
print('Killing postmaster. Losing Ptrack changes')
43-
node.pg_ctl('stop', {'-m': 'immediate', '-D': '{0}'.format(node.data_dir)})
43+
node.stop(['-m', 'immediate', '-D', node.data_dir])
4444
if not node.status():
4545
node.start()
4646
else:

tests/replica.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_replica_stream_ptrack_backup(self):
3939
self.set_replica(master, replica)
4040

4141
# Check data correctness on replica
42-
replica.start({"-t": "600"})
42+
replica.start(["-t", "600"])
4343
after = replica.safe_psql("postgres", "SELECT * FROM t_heap")
4444
self.assertEqual(before, after)
4545

@@ -120,7 +120,7 @@ def test_replica_archive_page_backup(self):
120120
# Settings for Replica
121121
self.set_replica(master, replica)
122122
self.set_archiving(backup_dir, 'replica', replica, replica=True)
123-
replica.start({"-t": "600"})
123+
replica.start(["-t", "600"])
124124

125125
# Check data correctness on replica
126126
after = replica.safe_psql("postgres", "SELECT * FROM t_heap")

tests/restore_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def test_restore_full_to_latest(self):
2020
initdb_params=['--data-checksums'],
2121
pg_options={'wal_level': 'replica'}
2222
)
23+
2324
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
2425
self.init_pb(backup_dir)
2526
self.add_instance(backup_dir, 'node', node)
@@ -126,7 +127,7 @@ def test_restore_to_specific_timeline(self):
126127
self.restore_node(backup_dir, 'node', node, options=["-j", "4"]),
127128
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(self.output), self.cmd))
128129

129-
node.start(params={'-t':'10'})
130+
node.start(params=['-t','10'])
130131
while node.safe_psql("postgres", "select pg_is_in_recovery()") == 't\n':
131132
time.sleep(1)
132133

0 commit comments

Comments
 (0)