From f98c91b3ba80fa2a149cd2fe26f3fd4d8c23be33 Mon Sep 17 00:00:00 2001 From: Grigory Smolkin Date: Wed, 11 Jul 2018 10:50:38 +0300 Subject: [PATCH] tests: add slow_start() method to PostgresNode --- tests/archive.py | 51 ++++----------- tests/compression.py | 36 ++++++---- tests/delta.py | 10 +-- tests/expected/option_help.out | 3 + tests/false_positive.py | 4 +- tests/helpers/ptrack_helpers.py | 21 ++++++ tests/page.py | 55 ++++++---------- tests/ptrack.py | 43 +++--------- tests/restore_test.py | 112 ++++++-------------------------- tests/validate_test.py | 2 +- 10 files changed, 116 insertions(+), 221 deletions(-) diff --git a/tests/archive.py b/tests/archive.py index 97fdca64..6cd86e7d 100644 --- a/tests/archive.py +++ b/tests/archive.py @@ -45,10 +45,7 @@ class ArchiveTest(ProbackupTest, unittest.TestCase): self.restore_node( backup_dir, 'node', node) - node.start() - while node.psql( - "postgres", "select pg_is_in_recovery()")[0] != 0: - sleep(1) + node.slow_start() # Recreate backup calagoue self.init_pb(backup_dir) @@ -64,10 +61,7 @@ class ArchiveTest(ProbackupTest, unittest.TestCase): self.restore_node( backup_dir, 'node', node, options=["--recovery-target-action=promote"]) - node.start() - while node.psql( - "postgres", "select pg_is_in_recovery()")[0] != 0: - sleep(1) + node.slow_start() self.assertEqual( result, node.safe_psql("postgres", "SELECT * FROM t_heap"), @@ -115,10 +109,8 @@ class ArchiveTest(ProbackupTest, unittest.TestCase): self.restore_node( backup_dir, 'node', node, options=['--immediate', '--recovery-target-action=promote']) - node.start() - while node.psql( - "postgres", "select pg_is_in_recovery()")[0] != 0: - sleep(1) + node.slow_start() + if self.verbose: print(node.safe_psql( "postgres", @@ -149,10 +141,7 @@ class ArchiveTest(ProbackupTest, unittest.TestCase): self.restore_node( backup_dir, 'node', node, options=['--immediate', '--recovery-target-action=promote']) - node.start() - while node.psql( - "postgres", "select pg_is_in_recovery()")[0] != 0: - sleep(1) + node.slow_start() if self.verbose: print( @@ -180,10 +169,7 @@ class ArchiveTest(ProbackupTest, unittest.TestCase): self.restore_node( backup_dir, 'node', node, options=['--immediate', '--recovery-target-action=promote']) - node.start() - while node.psql( - "postgres", "select pg_is_in_recovery()")[0] != 0: - sleep(1) + node.slow_start() if self.verbose: print('Fourth timeline') @@ -196,10 +182,8 @@ class ArchiveTest(ProbackupTest, unittest.TestCase): self.restore_node( backup_dir, 'node', node, options=['--immediate', '--recovery-target-action=promote']) - node.start() - while node.psql( - "postgres", "select pg_is_in_recovery()")[0] != 0: - sleep(1) + node.slow_start() + if self.verbose: print('Fifth timeline') print(node.safe_psql( @@ -211,10 +195,8 @@ class ArchiveTest(ProbackupTest, unittest.TestCase): self.restore_node( backup_dir, 'node', node, options=['--immediate', '--recovery-target-action=promote']) - node.start() - while node.psql( - "postgres", "select pg_is_in_recovery()")[0] != 0: - sleep(1) + node.slow_start() + if self.verbose: print('Sixth timeline') print(node.safe_psql( @@ -459,7 +441,7 @@ class ArchiveTest(ProbackupTest, unittest.TestCase): # Settings for Replica self.restore_node(backup_dir, 'master', replica) self.set_replica(master, replica, synchronous=True) - exit(1) + self.add_instance(backup_dir, 'replica', replica) self.set_archiving(backup_dir, 'replica', replica, replica=True) replica.start() @@ -768,10 +750,7 @@ class ArchiveTest(ProbackupTest, unittest.TestCase): # Check data correctness node.cleanup() self.restore_node(backup_dir, 'node', node) - node.start() - while node.psql( - "postgres", "select pg_is_in_recovery()")[0] != 0: - sleep(1) + node.slow_start() self.assertEqual( result, @@ -843,11 +822,7 @@ class ArchiveTest(ProbackupTest, unittest.TestCase): # Check data correctness node.cleanup() self.restore_node(backup_dir, 'node', node) - node.start() - - while node.psql( - "postgres", "select pg_is_in_recovery()")[0] != 0: - sleep(1) + node.slow_start() self.assertEqual( result, node.safe_psql("postgres", "SELECT * FROM t_heap"), diff --git a/tests/compression.py b/tests/compression.py index eff42963..aa275382 100644 --- a/tests/compression.py +++ b/tests/compression.py @@ -83,7 +83,8 @@ class CompressionTest(ProbackupTest, unittest.TestCase): "--recovery-target-action=promote"]), '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() + node.slow_start() + full_result_new = node.execute("postgres", "SELECT * FROM t_heap") self.assertEqual(full_result, full_result_new) node.cleanup() @@ -98,7 +99,8 @@ class CompressionTest(ProbackupTest, unittest.TestCase): "--recovery-target-action=promote"]), '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() + node.slow_start() + page_result_new = node.execute("postgres", "SELECT * FROM t_heap") self.assertEqual(page_result, page_result_new) node.cleanup() @@ -113,7 +115,8 @@ class CompressionTest(ProbackupTest, unittest.TestCase): "--recovery-target-action=promote"]), '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() + node.slow_start() + ptrack_result_new = node.execute("postgres", "SELECT * FROM t_heap") self.assertEqual(ptrack_result, ptrack_result_new) node.cleanup() @@ -187,7 +190,8 @@ class CompressionTest(ProbackupTest, unittest.TestCase): "--recovery-target-action=promote"]), '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() + node.slow_start() + full_result_new = node.execute("postgres", "SELECT * FROM t_heap") self.assertEqual(full_result, full_result_new) node.cleanup() @@ -202,7 +206,8 @@ class CompressionTest(ProbackupTest, unittest.TestCase): "--recovery-target-action=promote"]), '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() + node.slow_start() + page_result_new = node.execute("postgres", "SELECT * FROM t_heap") self.assertEqual(page_result, page_result_new) node.cleanup() @@ -217,7 +222,8 @@ class CompressionTest(ProbackupTest, unittest.TestCase): "--recovery-target-action=promote"]), '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() + node.slow_start() + ptrack_result_new = node.execute("postgres", "SELECT * FROM t_heap") self.assertEqual(ptrack_result, ptrack_result_new) node.cleanup() @@ -294,7 +300,8 @@ class CompressionTest(ProbackupTest, unittest.TestCase): "--recovery-target-action=promote"]), '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() + node.slow_start() + full_result_new = node.execute("postgres", "SELECT * FROM t_heap") self.assertEqual(full_result, full_result_new) node.cleanup() @@ -309,7 +316,8 @@ class CompressionTest(ProbackupTest, unittest.TestCase): "--recovery-target-action=promote"]), '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() + node.slow_start() + page_result_new = node.execute("postgres", "SELECT * FROM t_heap") self.assertEqual(page_result, page_result_new) node.cleanup() @@ -324,7 +332,8 @@ class CompressionTest(ProbackupTest, unittest.TestCase): "--recovery-target-action=promote"]), '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() + node.slow_start() + ptrack_result_new = node.execute("postgres", "SELECT * FROM t_heap") self.assertEqual(ptrack_result, ptrack_result_new) node.cleanup() @@ -401,7 +410,8 @@ class CompressionTest(ProbackupTest, unittest.TestCase): "--recovery-target-action=promote"]), '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() + node.slow_start() + full_result_new = node.execute("postgres", "SELECT * FROM t_heap") self.assertEqual(full_result, full_result_new) node.cleanup() @@ -416,7 +426,8 @@ class CompressionTest(ProbackupTest, unittest.TestCase): "--recovery-target-action=promote"]), '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() + node.slow_start() + page_result_new = node.execute("postgres", "SELECT * FROM t_heap") self.assertEqual(page_result, page_result_new) node.cleanup() @@ -431,7 +442,8 @@ class CompressionTest(ProbackupTest, unittest.TestCase): "--recovery-target-action=promote"]), '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() + node.slow_start() + ptrack_result_new = node.execute("postgres", "SELECT * FROM t_heap") self.assertEqual(ptrack_result, ptrack_result_new) node.cleanup() diff --git a/tests/delta.py b/tests/delta.py index 7cf21758..40450016 100644 --- a/tests/delta.py +++ b/tests/delta.py @@ -508,10 +508,7 @@ class DeltaTest(ProbackupTest, unittest.TestCase): # START RESTORED NODE restored_node.append_conf( "postgresql.auto.conf", "port = {0}".format(restored_node.port)) - restored_node.start() - while restored_node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) + restored_node.slow_start() result_new = restored_node.safe_psql( "postgres", "select * from pgbench_accounts") @@ -946,11 +943,8 @@ class DeltaTest(ProbackupTest, unittest.TestCase): # START RESTORED NODE node_restored.append_conf( 'postgresql.auto.conf', 'port = {0}'.format(node_restored.port)) - node_restored.start() + node_restored.slow_start() - while node_restored.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) result_new = node_restored.safe_psql( "postgres", "select * from t_heap") diff --git a/tests/expected/option_help.out b/tests/expected/option_help.out index 4080f4b8..a72aada8 100644 --- a/tests/expected/option_help.out +++ b/tests/expected/option_help.out @@ -25,6 +25,7 @@ pg_probackup - utility to manage backup/recovery of PostgreSQL database. [--replica-timeout=timeout] pg_probackup show-config -B backup-dir --instance=instance_name + [--format=format] pg_probackup backup -B backup-path -b backup-mode --instance=instance_name [-C] [--stream [-S slot-name]] [--backup-pg-log] @@ -61,10 +62,12 @@ pg_probackup - utility to manage backup/recovery of PostgreSQL database. pg_probackup validate -B backup-dir [--instance=instance_name] [-i backup-id] [--progress] [--time=time|--xid=xid [--inclusive=boolean]] + [--recovery-target-name=target-name] [--timeline=timeline] pg_probackup show -B backup-dir [--instance=instance_name [-i backup-id]] + [--format=format] pg_probackup delete -B backup-dir --instance=instance_name [--wal] [-i backup-id | --expired] diff --git a/tests/false_positive.py b/tests/false_positive.py index 909d69fc..1884159b 100644 --- a/tests/false_positive.py +++ b/tests/false_positive.py @@ -191,7 +191,7 @@ class FalsePositive(ProbackupTest, unittest.TestCase): node.data_dir, ignore_ptrack=False) self.compare_pgdata(pgdata, pgdata_restored) - node.start() + node.slow_start() # Logical comparison self.assertEqual( result, @@ -290,7 +290,7 @@ class FalsePositive(ProbackupTest, unittest.TestCase): node.data_dir, ignore_ptrack=False) self.compare_pgdata(pgdata, pgdata_restored) - node.start() + node.slow_start() # Logical comparison self.assertEqual( result, diff --git a/tests/helpers/ptrack_helpers.py b/tests/helpers/ptrack_helpers.py index af7fe766..4cdd8836 100644 --- a/tests/helpers/ptrack_helpers.py +++ b/tests/helpers/ptrack_helpers.py @@ -112,6 +112,25 @@ class ProbackupException(Exception): return '\n ERROR: {0}\n CMD: {1}'.format(repr(self.message), self.cmd) +def slow_start(self): + + # wait for https://github.com/postgrespro/testgres/pull/50 + # self.poll_query_until( + # "postgres", + # "SELECT not pg_is_in_recovery()", + # raise_operational_error=False) + + self.start() + while True: + try: + self.poll_query_until( + "postgres", + "SELECT not pg_is_in_recovery()") + break + except Exception as e: + continue + + class ProbackupTest(object): # Class attributes enterprise = is_enterprise() @@ -205,6 +224,8 @@ class ProbackupTest(object): os.makedirs(real_base_dir) node = testgres.get_new_node('test', base_dir=real_base_dir) + # bound method slow_start() to 'node' class instance + node.slow_start = slow_start.__get__(node) node.should_rm_dirs = True node.init( initdb_params=initdb_params, allow_streaming=set_replication) diff --git a/tests/page.py b/tests/page.py index 9a7260c2..c3ca6ee9 100644 --- a/tests/page.py +++ b/tests/page.py @@ -3,7 +3,6 @@ import unittest from .helpers.ptrack_helpers import ProbackupTest, ProbackupException from datetime import datetime, timedelta import subprocess -import time module_name = 'page' @@ -33,8 +32,7 @@ class PageBackupTest(ProbackupTest, unittest.TestCase): } ) node_restored = self.make_simple_node( - base_dir="{0}/{1}/node_restored".format(module_name, fname), - ) + base_dir="{0}/{1}/node_restored".format(module_name, fname)) self.init_pb(backup_dir) self.add_instance(backup_dir, 'node', node) @@ -49,32 +47,27 @@ class PageBackupTest(ProbackupTest, unittest.TestCase): "create table t_heap tablespace somedata as select i as id, " "md5(i::text) as text, " "md5(repeat(i::text,10))::tsvector as tsvector " - "from generate_series(0,1024) i;" - ) + "from generate_series(0,1024) i;") + node.safe_psql( "postgres", - "vacuum t_heap" - ) + "vacuum t_heap") self.backup_node(backup_dir, 'node', node) node.safe_psql( "postgres", - "delete from t_heap where ctid >= '(11,0)'" - ) + "delete from t_heap where ctid >= '(11,0)'") node.safe_psql( "postgres", - "vacuum t_heap" - ) + "vacuum t_heap") self.backup_node( backup_dir, 'node', node, backup_type='page', - options=['--log-level-file=verbose'] - ) + options=['--log-level-file=verbose']) self.backup_node( - backup_dir, 'node', node, backup_type='page' - ) + backup_dir, 'node', node, backup_type='page') if self.paranoia: pgdata = self.pgdata_content(node.data_dir) @@ -87,8 +80,7 @@ class PageBackupTest(ProbackupTest, unittest.TestCase): options=[ "-j", "4", "-T", "{0}={1}".format(old_tablespace, new_tablespace), - "--recovery-target-action=promote"] - ) + "--recovery-target-action=promote"]) # Physical comparison if self.paranoia: @@ -97,21 +89,17 @@ class PageBackupTest(ProbackupTest, unittest.TestCase): node_restored.append_conf( "postgresql.auto.conf", "port = {0}".format(node_restored.port)) - node_restored.start() - - while node_restored.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) + node_restored.slow_start() # Logical comparison result1 = node.safe_psql( "postgres", - "select * from t_heap" - ) + "select * from t_heap") + result2 = node_restored.safe_psql( "postgres", - "select * from t_heap" - ) + "select * from t_heap") + self.assertEqual(result1, result2) # Clean after yourself @@ -175,7 +163,7 @@ class PageBackupTest(ProbackupTest, unittest.TestCase): backup_id=full_backup_id, options=["-j", "4"]), '\n Unexpected Error Message: {0}\n' ' CMD: {1}'.format(repr(self.output), self.cmd)) - node.start() + node.slow_start() full_result_new = node.execute("postgres", "SELECT * FROM t_heap") self.assertEqual(full_result, full_result_new) node.cleanup() @@ -188,7 +176,7 @@ class PageBackupTest(ProbackupTest, unittest.TestCase): backup_id=page_backup_id, options=["-j", "4"]), '\n Unexpected Error Message: {0}\n' ' CMD: {1}'.format(repr(self.output), self.cmd)) - node.start() + node.slow_start() page_result_new = node.execute("postgres", "SELECT * FROM t_heap") self.assertEqual(page_result, page_result_new) node.cleanup() @@ -254,7 +242,8 @@ class PageBackupTest(ProbackupTest, unittest.TestCase): "--recovery-target-action=promote"]), '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() + node.slow_start() + full_result_new = node.execute("postgres", "SELECT * FROM t_heap") self.assertEqual(full_result, full_result_new) node.cleanup() @@ -271,7 +260,8 @@ class PageBackupTest(ProbackupTest, unittest.TestCase): "--recovery-target-action=promote"]), '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() + node.slow_start() + page_result_new = node.execute("postgres", "SELECT * FROM t_heap") self.assertEqual(page_result, page_result_new) node.cleanup() @@ -349,10 +339,7 @@ class PageBackupTest(ProbackupTest, unittest.TestCase): # START RESTORED NODE restored_node.append_conf( "postgresql.auto.conf", "port = {0}".format(restored_node.port)) - restored_node.start() - while restored_node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) + restored_node.slow_start() result_new = restored_node.safe_psql( "postgres", "select * from pgbench_accounts") diff --git a/tests/ptrack.py b/tests/ptrack.py index 4823acef..c2d6abff 100644 --- a/tests/ptrack.py +++ b/tests/ptrack.py @@ -586,10 +586,7 @@ class PtrackTest(ProbackupTest, unittest.TestCase): '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd) ) - node.start() - while node.psql( - "postgres", "select pg_is_in_recovery()")[0] != 0: - time.sleep(1) + node.slow_start() full_result_new = node.safe_psql("postgres", "SELECT * FROM t_heap") self.assertEqual(full_result, full_result_new) node.cleanup() @@ -611,10 +608,7 @@ class PtrackTest(ProbackupTest, unittest.TestCase): node.data_dir, ignore_ptrack=False) self.compare_pgdata(pgdata, pgdata_restored) - node.start() - while node.psql( - "postgres", "select pg_is_in_recovery()")[0] != 0: - time.sleep(1) + node.slow_start() ptrack_result_new = node.safe_psql("postgres", "SELECT * FROM t_heap") self.assertEqual(ptrack_result, ptrack_result_new) @@ -691,11 +685,7 @@ class PtrackTest(ProbackupTest, unittest.TestCase): '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd) ) - node.start() - - while node.psql( - "postgres", "select pg_is_in_recovery()")[0] != 0: - time.sleep(1) + node.slow_start() full_result_new = node.safe_psql("postgres", "SELECT * FROM t_heap") self.assertEqual(full_result, full_result_new) @@ -721,10 +711,7 @@ class PtrackTest(ProbackupTest, unittest.TestCase): node.data_dir, ignore_ptrack=False) self.compare_pgdata(pgdata, pgdata_restored) - node.start() - while node.psql( - "postgres", "select pg_is_in_recovery()")[0] != 0: - time.sleep(1) + node.slow_start() ptrack_result_new = node.safe_psql("postgres", "SELECT * FROM t_heap") self.assertEqual(ptrack_result, ptrack_result_new) @@ -1176,11 +1163,8 @@ class PtrackTest(ProbackupTest, unittest.TestCase): # START RESTORED NODE node_restored.append_conf( 'postgresql.auto.conf', 'port = {0}'.format(node_restored.port)) - node_restored.start() + node_restored.slow_start() - while node_restored.psql( - "postgres", "select pg_is_in_recovery()")[0] != 0: - time.sleep(1) result_new = node_restored.safe_psql( "postgres", "select * from t_heap") @@ -1412,10 +1396,7 @@ class PtrackTest(ProbackupTest, unittest.TestCase): # START RESTORED NODE restored_node.append_conf( "postgresql.auto.conf", "port = {0}".format(restored_node.port)) - restored_node.start() - while restored_node.psql( - "postgres", "select pg_is_in_recovery()")[0] != 0: - time.sleep(1) + restored_node.slow_start() # COMPARE LOGICAL CONTENT result_new = restored_node.safe_psql( @@ -1450,11 +1431,7 @@ class PtrackTest(ProbackupTest, unittest.TestCase): # START RESTORED NODE restored_node.append_conf( "postgresql.auto.conf", "port = {0}".format(restored_node.port)) - restored_node.start() - while restored_node.psql( - "postgres", - "select pg_is_in_recovery()") == 't\n': - time.sleep(1) + restored_node.slow_start() result_new = restored_node.safe_psql( "postgres", "select * from t_heap") @@ -1553,11 +1530,7 @@ class PtrackTest(ProbackupTest, unittest.TestCase): # START RESTORED NODE restored_node.append_conf( "postgresql.auto.conf", "port = {0}".format(restored_node.port)) - restored_node.start() - while restored_node.psql( - "postgres", - "select pg_is_in_recovery()") == 't\n': - time.sleep(1) + restored_node.slow_start() result_new = restored_node.safe_psql( "postgres", diff --git a/tests/restore_test.py b/tests/restore_test.py index fce96911..862c8662 100644 --- a/tests/restore_test.py +++ b/tests/restore_test.py @@ -53,10 +53,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase): recovery_conf = os.path.join(node.data_dir, "recovery.conf") self.assertEqual(os.path.isfile(recovery_conf), True) - node.start() - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) + node.slow_start() after = node.execute("postgres", "SELECT * FROM pgbench_branches") self.assertEqual(before, after) @@ -104,10 +101,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase): '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) + node.slow_start() after = node.execute("postgres", "SELECT * FROM pgbench_branches") self.assertEqual(before, after) @@ -149,11 +143,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase): '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start(params=['-t', '10']) - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) - + node.slow_start() pgbench = node.pgbench( stdout=subprocess.PIPE, stderr=subprocess.STDOUT, options=['-T', '10', '-c', '2', '--no-vacuum']) @@ -181,11 +171,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase): node)["recovery_target_timeline"] self.assertEqual(int(recovery_target_timeline), target_tli) - node.start() - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) - + node.slow_start() after = node.execute("postgres", "SELECT * FROM pgbench_branches") self.assertEqual(before, after) @@ -234,11 +220,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase): '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) - + node.slow_start() after = node.execute("postgres", "SELECT * FROM pgbench_branches") self.assertEqual(before, after) @@ -297,11 +279,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase): '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) - + node.slow_start() after = node.safe_psql("postgres", "SELECT * FROM pgbench_branches") self.assertEqual(before, after) self.assertEqual( @@ -366,11 +344,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase): '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) - + node.slow_start() after = node.execute("postgres", "SELECT * FROM pgbench_branches") self.assertEqual(before, after) self.assertEqual( @@ -420,11 +394,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase): '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) - + node.slow_start() after = node.execute("postgres", "SELECT * FROM pgbench_branches") self.assertEqual(before, after) @@ -479,11 +449,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase): '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) - + node.slow_start() after = node.execute("postgres", "SELECT * FROM pgbench_branches") self.assertEqual(before, after) @@ -535,11 +501,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase): '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) - + node.slow_start() after = node.execute("postgres", "SELECT * FROM pgbench_branches") self.assertEqual(before, after) @@ -602,11 +564,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase): '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) - + node.slow_start() bbalance = node.execute( "postgres", "SELECT sum(bbalance) FROM pgbench_branches") delta = node.execute( @@ -674,11 +632,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase): options=["-j", "4", "--recovery-target-action=promote"]), '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) - + node.slow_start() bbalance = node.execute( "postgres", "SELECT sum(bbalance) FROM pgbench_branches") delta = node.execute( @@ -769,10 +723,8 @@ class RestoreTest(ProbackupTest, unittest.TestCase): '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) + node.slow_start() + result = node.execute("postgres", "SELECT id FROM test") self.assertEqual(result[0][0], 1) @@ -802,10 +754,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase): '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) + node.slow_start() result = node.execute("postgres", "SELECT id FROM test OFFSET 1") self.assertEqual(result[0][0], 2) @@ -881,10 +830,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase): "--recovery-target-action=promote"]), '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) + node.slow_start() count = node.execute("postgres", "SELECT count(*) FROM tbl") self.assertEqual(count[0][0], 4) @@ -935,10 +881,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase): '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) + node.slow_start() result = node.psql("postgres", 'select * from t_heap') self.assertTrue('does not exist' in result[2].decode("utf-8")) @@ -987,11 +930,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase): '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) - + node.slow_start() result = node.psql("postgres", 'select * from t_heap') self.assertTrue('does not exist' in result[2].decode("utf-8")) @@ -1039,10 +978,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase): '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(self.output), self.cmd)) - node.start() - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) + node.slow_start() result = node.psql("postgres", 'select * from t_heap') self.assertEqual(True, 'does not exist' in result[2].decode("utf-8")) @@ -1097,10 +1033,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase): pgdata_restored = self.pgdata_content(node.data_dir) self.compare_pgdata(pgdata, pgdata_restored) - node.start() - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) + node.slow_start() result = node.psql("postgres", 'select * from t_heap') self.assertTrue('does not exist' in result[2].decode("utf-8")) @@ -1149,10 +1082,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase): "--recovery-target-name=savepoint", "--recovery-target-action=promote"]) - node.start() - while node.safe_psql( - "postgres", "select pg_is_in_recovery()") == 't\n': - time.sleep(1) + node.slow_start() result_new = node.safe_psql("postgres", "select * from t_heap") res = node.psql("postgres", "select * from t_heap_1") diff --git a/tests/validate_test.py b/tests/validate_test.py index afb2305f..29800bc9 100644 --- a/tests/validate_test.py +++ b/tests/validate_test.py @@ -1320,7 +1320,7 @@ class ValidateTest(ProbackupTest, unittest.TestCase): self.restore_node(backup_dir, 'node1', data_dir=node2.data_dir) node2.append_conf( 'postgresql.auto.conf', 'port = {0}'.format(node2.port)) - node2.start() + node2.slow_start() timeline_node1 = node1.get_control_data()["Latest checkpoint's TimeLineID"] timeline_node2 = node2.get_control_data()["Latest checkpoint's TimeLineID"]