Skip to content

Commit b52ee32

Browse files
committed
tests: minor fixes
1 parent 57ca17a commit b52ee32

File tree

4 files changed

+58
-161
lines changed

4 files changed

+58
-161
lines changed

tests/archive.py

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import shutil
33
import gzip
44
import unittest
5-
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException, archive_script
5+
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException, GdbException
66
from datetime import datetime, timedelta
77
import subprocess
88
from sys import exit
@@ -221,7 +221,10 @@ def test_pgpro434_2(self):
221221

222222
# @unittest.skip("skip")
223223
def test_pgpro434_3(self):
224-
"""Check pg_stop_backup_timeout, needed backup_timeout"""
224+
"""
225+
Check pg_stop_backup_timeout, needed backup_timeout
226+
Fixed in commit d84d79668b0c139 and assert fixed by ptrack 1.7
227+
"""
225228
fname = self.id().split('.')[3]
226229
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
227230
node = self.make_simple_node(
@@ -236,40 +239,32 @@ def test_pgpro434_3(self):
236239
self.add_instance(backup_dir, 'node', node)
237240
self.set_archiving(backup_dir, 'node', node)
238241

239-
archive_script_path = os.path.join(backup_dir, 'archive_script.sh')
240-
with open(archive_script_path, 'w+') as f:
241-
f.write(
242-
archive_script.format(
243-
backup_dir=backup_dir, node_name='node', count_limit=2))
244-
245-
st = os.stat(archive_script_path)
246-
os.chmod(archive_script_path, st.st_mode | 0o111)
247-
node.append_conf(
248-
'postgresql.auto.conf', "archive_command = '{0} %p %f'".format(
249-
archive_script_path))
250-
251242
node.slow_start()
252243

253-
try:
254-
self.backup_node(
244+
gdb = self.backup_node(
255245
backup_dir, 'node', node,
256246
options=[
257247
"--archive-timeout=60",
258-
"--stream"]
259-
)
260-
# we should die here because exception is what we expect to happen
261-
self.assertEqual(
262-
1, 0,
263-
"Expecting Error because pg_stop_backup failed to answer.\n "
264-
"Output: {0} \n CMD: {1}".format(
265-
repr(self.output), self.cmd))
266-
267-
except ProbackupException as e:
268-
self.assertTrue(
269-
"ERROR: pg_stop_backup doesn't answer" in e.message and
270-
"cancel it" in e.message,
271-
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
272-
repr(e.message), self.cmd))
248+
"--stream",
249+
"--log-level-file=info"],
250+
gdb=True)
251+
252+
gdb.set_breakpoint('pg_stop_backup')
253+
gdb.run_until_break()
254+
255+
node.append_conf(
256+
'postgresql.auto.conf', "archive_command = 'exit 1'")
257+
node.reload()
258+
259+
gdb.continue_execution_until_exit()
260+
261+
log_file = os.path.join(backup_dir, 'log/pg_probackup.log')
262+
with open(log_file, 'r') as f:
263+
log_content = f.read()
264+
self.assertNotIn(
265+
"ERROR: pg_stop_backup doesn't answer",
266+
log_content,
267+
"pg_stop_backup timeouted")
273268

274269
log_file = os.path.join(node.logs_dir, 'postgresql.log')
275270
with open(log_file, 'r') as f:
@@ -331,6 +326,7 @@ def test_arhive_push_file_exists(self):
331326

332327
wal_src = os.path.join(
333328
node.data_dir, 'pg_wal', '000000010000000000000001')
329+
334330
if self.archive_compress:
335331
with open(wal_src, 'rb') as f_in, gzip.open(
336332
file, 'wb', compresslevel=1) as f_out:
@@ -412,7 +408,7 @@ def test_arhive_push_file_exists_overwrite(self):
412408
self.del_test_dir(module_name, fname)
413409

414410
# @unittest.expectedFailure
415-
@unittest.skip("skip")
411+
# @unittest.skip("skip")
416412
def test_replica_archive(self):
417413
"""
418414
make node without archiving, take stream backup and
@@ -502,19 +498,21 @@ def test_replica_archive(self):
502498
"postgres",
503499
"insert into t_heap as select i as id, md5(i::text) as text, "
504500
"md5(repeat(i::text,10))::tsvector as tsvector "
505-
"from generate_series(512,20680) i")
501+
"from generate_series(512,80680) i")
506502

507503
before = master.safe_psql("postgres", "SELECT * FROM t_heap")
508504

509505
master.safe_psql(
510506
"postgres",
511507
"CHECKPOINT")
512508

509+
self.wait_until_replica_catch_with_master(master, replica)
510+
513511
backup_id = self.backup_node(
514512
backup_dir, 'replica',
515513
replica, backup_type='page',
516514
options=[
517-
'--archive-timeout=30',
515+
'--archive-timeout=60',
518516
'--master-db=postgres',
519517
'--master-host=localhost',
520518
'--master-port={0}'.format(master.port),

tests/helpers/ptrack_helpers.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,6 @@
6060
}
6161
}
6262

63-
archive_script = """
64-
#!/bin/bash
65-
count=$(ls {backup_dir}/test00* | wc -l)
66-
if [ $count -ge {count_limit} ]
67-
then
68-
exit 1
69-
else
70-
cp $1 {backup_dir}/wal/{node_name}/$2
71-
count=$((count+1))
72-
touch {backup_dir}/test00$count
73-
exit 0
74-
fi
75-
"""
7663
warning = """
7764
Wrong splint in show_pb
7865
Original Header:

tests/page.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
44
from datetime import datetime, timedelta
55
import subprocess
6+
import gzip
7+
import shutil
68

79
module_name = 'page'
810

@@ -781,7 +783,22 @@ def test_page_backup_with_corrupted_wal_segment(self):
781783
wals_dir, f)) and not f.endswith('.backup')]
782784
wals = map(str, wals)
783785
# file = os.path.join(wals_dir, max(wals))
784-
file = os.path.join(wals_dir, '000000010000000000000004')
786+
787+
if self.archive_compress:
788+
original_file = os.path.join(wals_dir, '000000010000000000000004.gz')
789+
tmp_file = os.path.join(backup_dir, '000000010000000000000004')
790+
791+
with gzip.open(original_file, 'rb') as f_in, open(tmp_file, 'wb') as f_out:
792+
shutil.copyfileobj(f_in, f_out)
793+
794+
# drop healthy file
795+
os.remove(original_file)
796+
file = tmp_file
797+
798+
else:
799+
file = os.path.join(wals_dir, '000000010000000000000004')
800+
801+
# corrupt file
785802
print(file)
786803
with open(file, "rb+", 0) as f:
787804
f.seek(42)
@@ -790,7 +807,14 @@ def test_page_backup_with_corrupted_wal_segment(self):
790807
f.close
791808

792809
if self.archive_compress:
793-
file = file[:-3]
810+
# compress corrupted file and replace with it old file
811+
with open(file, 'rb') as f_in, gzip.open(original_file, 'wb', compresslevel=1) as f_out:
812+
shutil.copyfileobj(f_in, f_out)
813+
814+
file = os.path.join(wals_dir, '000000010000000000000004.gz')
815+
816+
#if self.archive_compress:
817+
# file = file[:-3]
794818

795819
# Single-thread PAGE backup
796820
try:
@@ -915,9 +939,6 @@ def test_page_backup_with_alien_wal_segment(self):
915939
print(file_destination)
916940
os.rename(file, file_destination)
917941

918-
if self.archive_compress:
919-
file_destination = file_destination[:-3]
920-
921942
# Single-thread PAGE backup
922943
try:
923944
self.backup_node(

tests/replica.py

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,6 @@ def test_replica_archive_page_backup(self):
236236
pgbench = master.pgbench(
237237
options=['-T', '30', '-c', '2', '--no-vacuum'])
238238

239-
# master.psql(
240-
# "postgres",
241-
# "insert into t_heap as select i as id, md5(i::text) as text, "
242-
# "md5(repeat(i::text,10))::tsvector as tsvector "
243-
# "from generate_series(512,25120) i")
244-
245239
backup_id = self.backup_node(
246240
backup_dir, 'replica',
247241
replica, backup_type='page',
@@ -449,106 +443,3 @@ def test_take_backup_from_delayed_replica(self):
449443

450444
# Clean after yourself
451445
self.del_test_dir(module_name, fname)
452-
453-
@unittest.skip("skip")
454-
def test_make_block_from_future(self):
455-
"""
456-
make archive master, take full backups from master,
457-
restore full backup as replica, launch pgbench,
458-
"""
459-
fname = self.id().split('.')[3]
460-
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
461-
master = self.make_simple_node(
462-
base_dir="{0}/{1}/master".format(module_name, fname),
463-
set_replication=True,
464-
initdb_params=['--data-checksums'],
465-
pg_options={
466-
'wal_level': 'replica',
467-
'max_wal_senders': '2'}
468-
)
469-
self.init_pb(backup_dir)
470-
self.add_instance(backup_dir, 'master', master)
471-
self.set_archiving(backup_dir, 'master', master)
472-
# force more frequent wal switch
473-
#master.append_conf('postgresql.auto.conf', 'archive_timeout = 10')
474-
master.slow_start()
475-
476-
replica = self.make_simple_node(
477-
base_dir="{0}/{1}/replica".format(module_name, fname))
478-
replica.cleanup()
479-
480-
self.backup_node(backup_dir, 'master', master)
481-
482-
self.restore_node(
483-
backup_dir, 'master', replica, options=['-R'])
484-
485-
# Settings for Replica
486-
self.set_archiving(backup_dir, 'replica', replica, replica=True)
487-
replica.append_conf(
488-
'postgresql.auto.conf', 'port = {0}'.format(replica.port))
489-
replica.append_conf(
490-
'postgresql.auto.conf', 'hot_standby = on')
491-
492-
replica.slow_start(replica=True)
493-
494-
self.add_instance(backup_dir, 'replica', replica)
495-
496-
replica.safe_psql(
497-
'postgres',
498-
'checkpoint')
499-
500-
master.pgbench_init(scale=10)
501-
502-
self.wait_until_replica_catch_with_master(master, replica)
503-
504-
505-
# print(replica.safe_psql(
506-
# 'postgres',
507-
# 'select * from pg_catalog.pg_last_xlog_receive_location()'))
508-
#
509-
# print(replica.safe_psql(
510-
# 'postgres',
511-
# 'select * from pg_catalog.pg_last_xlog_replay_location()'))
512-
#
513-
# print(replica.safe_psql(
514-
# 'postgres',
515-
# 'select * from pg_catalog.pg_control_checkpoint()'))
516-
#
517-
# replica.safe_psql(
518-
# 'postgres',
519-
# 'checkpoint')
520-
521-
pgbench = master.pgbench(options=['-T', '30', '-c', '2', '--no-vacuum'])
522-
523-
time.sleep(5)
524-
525-
#self.backup_node(backup_dir, 'replica', replica, options=['--stream'])
526-
exit(1)
527-
self.backup_node(backup_dir, 'replica', replica)
528-
pgbench.wait()
529-
530-
# pgbench
531-
master.safe_psql(
532-
"postgres",
533-
"create table t_heap as select i as id, md5(i::text) as text, "
534-
"md5(repeat(i::text,10))::tsvector as tsvector "
535-
"from generate_series(0,256000) i")
536-
537-
538-
master.safe_psql(
539-
'postgres',
540-
'checkpoint')
541-
542-
replica.safe_psql(
543-
'postgres',
544-
'checkpoint')
545-
546-
replica.safe_psql(
547-
'postgres',
548-
'select * from pg_')
549-
550-
self.backup_node(backup_dir, 'replica', replica)
551-
exit(1)
552-
553-
# Clean after yourself
554-
self.del_test_dir(module_name, fname)

0 commit comments

Comments
 (0)