1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-09-16 09:26:30 +02:00

[PBCKP-287] improves for @unittest.skipUnless(ProbackupTest.gdb) GDB tests

This commit is contained in:
Ivan Lazarev
2022-11-22 02:43:47 +03:00
parent 97f3e70edb
commit 07d21334d2
2 changed files with 90 additions and 10 deletions

View File

@@ -8,15 +8,90 @@ from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
tblspace_name = 'cfs_tblspace'
class CfsValidateBackupNoenc(ProbackupTest,unittest.TestCase):
def setUp(self):
pass
class CfsValidateBackupNoenc(ProbackupTest, unittest.TestCase):
def test_validate_fullbackup_empty_tablespace_after_delete_pg_compression(self):
pass
def tearDown(self):
pass
@unittest.skipUnless(ProbackupTest.enterprise, 'skip')
# TODO replace all ProbackupTest._check_gdb_flag_or_skip_test() by this check
@unittest.skipUnless(ProbackupTest.gdb, 'skip')
# TODO rename
def test_crash_on_postgres_cfs_gc_and_running_bad_backup_on_postgres_restart_before_postgres_cfs_recovery(self):
# TODO extract to setUp()
self.backup_dir = os.path.join(self.tmp_path, self.module_name, self.fname, 'backup')
self.node = self.make_simple_node(
base_dir="{0}/{1}/node".format(self.module_name, self.fname),
set_replication=True, #TODO make set_replication=False?????
initdb_params=['--data-checksums'],
pg_options={
# 'ptrack_enable': 'on',
'cfs_encryption': 'off',
}
)
self.init_pb(self.backup_dir)
self.add_instance(self.backup_dir, 'node', self.node)
self.set_archiving(self.backup_dir, 'node', self.node)
self.node.slow_start()
self.create_tblspace_in_node(self.node, tblspace_name, cfs=True)
# TODO END OF EXTRACTION to setUp() method
self.backup_id = None
try:
# TODO remove backup here?
self.backup_id = self.backup_node(self.backup_dir, 'node', self.node, backup_type='full')
except ProbackupException as e:
self.fail(
"ERROR: Full backup failed \n {0} \n {1}".format(
repr(self.cmd),
repr(e.message)
)
)
self.node.safe_psql(
"postgres",
'CREATE TABLE {0} TABLESPACE {1} \
AS SELECT i AS {0}_pkey, MD5(i::text) AS text, \
MD5(repeat(i::text,10))::tsvector AS tsvector \
FROM generate_series(0,1e4) i'.format('t1', tblspace_name)
# FROM generate_series(0,1e5) i'.format('t1', tblspace_name)
)
cfs_gc_pid = self.node.safe_psql(
"postgres",
"SELECT pid "
"FROM pg_stat_activity "
"WHERE application_name LIKE 'CFS GC worker%'")
self.verbose = True
gdb = self.gdb_attach(cfs_gc_pid)
gdb.set_breakpoint('cfs_gc_file')
self.node.safe_psql(
"postgres",
# "WITH i AS (select generate_series(1, 1e5) AS i) "
"WITH i AS (select generate_series(1, 1e4) AS i) "
"UPDATE {0}"
" SET text = MD5(MD5(i::text))"
" FROM i"
" WHERE {0}_pkey = i"
.format("t1")
)
gdb.continue_execution_until_break()
gdb.remove_all_breakpoints()
## gdb.continue_execution_until_break()
# gdb.continue_execution_until_running()
## gdb.continue_execution_until_exit()
## gdb.kill()
gdb._execute("detach")
self.node.cleanup()
print("hurray ")
#class CfsValidateBackupNoenc(CfsValidateBackupNoenc):

View File

@@ -1,6 +1,5 @@
# you need os for unittest to work
import os
import gc
import unittest
from sys import exit, argv, version_info
import subprocess
@@ -111,6 +110,10 @@ def is_nls_enabled():
return b'enable-nls' in p.communicate()[0]
def is_gdb_enabled():
return 'PGPROBACKUP_GDB' in os.environ and os.environ['PGPROBACKUP_GDB'] == 'ON'
def base36enc(number):
"""Converts an integer to a base36 string."""
alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
@@ -139,6 +142,7 @@ class ProbackupException(Exception):
def __str__(self):
return '\n ERROR: {0}\n CMD: {1}'.format(repr(self.message), self.cmd)
class PostgresNodeExtended(testgres.PostgresNode):
def __init__(self, base_dir=None, *args, **kwargs):
@@ -195,6 +199,7 @@ class ProbackupTest(object):
# Class attributes
enterprise = is_enterprise()
enable_nls = is_nls_enabled()
gdb = is_gdb_enabled()
def __init__(self, *args, **kwargs):
super(ProbackupTest, self).__init__(*args, **kwargs)
@@ -235,9 +240,6 @@ class ProbackupTest(object):
self.test_env['LC_MESSAGES'] = 'C'
self.test_env['LC_TIME'] = 'C'
self.gdb = 'PGPROBACKUP_GDB' in self.test_env and \
self.test_env['PGPROBACKUP_GDB'] == 'ON'
self.paranoia = 'PG_PROBACKUP_PARANOIA' in self.test_env and \
self.test_env['PG_PROBACKUP_PARANOIA'] == 'ON'
@@ -1972,7 +1974,10 @@ class ProbackupTest(object):
self.assertFalse(fail, error_message)
def gdb_attach(self, pid):
return GDBobj([str(pid)], self, attach=True)
if type(pid) is str: # python 2.7 compatibility
return GDBobj([pid.strip()], self, attach=True)
else: # python 3
return GDBobj([pid.decode("UTF-8").strip()], self, attach=True)
def _check_gdb_flag_or_skip_test(self):
if not self.gdb: