Skip to content

Commit 75d67e0

Browse files
author
Maksim Milyutin
committed
devnull pg_restore sdterr and stdout and augment descriptions of errors in test_pg_dump
1 parent ab61e1e commit 75d67e0

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

tests/python/partitioning_test.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ def test_pg_dump(self):
780780
con.commit()
781781

782782
# compare strategies
783+
CMP_OK, PLANS_MISMATCH, CONTENTS_MISMATCH = range(3)
783784
def cmp_full(con1, con2):
784785
"""Compare selection partitions in plan and contents in partitioned tables"""
785786

@@ -794,11 +795,15 @@ def cmp_full(con1, con2):
794795
for table_ref in table_refs:
795796
plan_initial = con1.execute(plan_query % table_ref)[0][0][0]['Plan']
796797
plan_copy = con2.execute(plan_query % table_ref)[0][0][0]['Plan']
797-
self.assertEqual(ordered(plan_initial), ordered(plan_copy))
798+
if ordered(plan_initial) != ordered(plan_copy):
799+
return PLANS_MISMATCH
798800

799801
content_initial = [x[0] for x in con1.execute(content_query % table_ref)]
800802
content_copy = [x[0] for x in con2.execute(content_query % table_ref)]
801-
self.assertEqual(content_initial, content_copy)
803+
if content_initial != content_copy:
804+
return CONTENTS_MISMATCH
805+
806+
return CMP_OK
802807

803808
def turnoff_pathman(node):
804809
node.psql('initial', 'alter system set pg_pathman.enable to off')
@@ -845,12 +850,15 @@ def turnon_pathman(node):
845850
]
846851
for preproc, postproc, pg_dump_params, pg_restore_params, cmp_dbs in test_params:
847852

853+
dump_restore_cmd = " | ".join((' '.join(pg_dump_params), ' '.join(pg_restore_params)))
854+
848855
if (preproc != None):
849856
preproc(node)
850857

851858
# transfer and restore data
859+
FNULL = open(os.devnull, 'w')
852860
p1 = subprocess.Popen(pg_dump_params, stdout=subprocess.PIPE)
853-
p2 = subprocess.Popen(pg_restore_params, stdin=p1.stdout, stdout=subprocess.PIPE)
861+
p2 = subprocess.Popen(pg_restore_params, stdin=p1.stdout, stdout=FNULL, stderr=FNULL)
854862
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
855863
p2.communicate()
856864

@@ -861,7 +869,11 @@ def turnon_pathman(node):
861869
with node.connect('initial') as con1, node.connect('copy') as con2:
862870

863871
# compare plans and contents of initial and copy
864-
cmp_dbs(con1, con2)
872+
cmp_result = cmp_dbs(con1, con2)
873+
self.assertNotEqual(cmp_result, PLANS_MISMATCH,
874+
"mismatch in plans of select query on partitioned tables under the command: %s" % dump_restore_cmd)
875+
self.assertNotEqual(cmp_result, CONTENTS_MISMATCH,
876+
"mismatch in contents of partitioned tables under the command: %s" % dump_restore_cmd)
865877

866878
# compare enable_parent flag and callback function
867879
config_params_query = """
@@ -872,7 +884,8 @@ def turnon_pathman(node):
872884
config_params_initial[row[0]] = row[1:]
873885
for row in con2.execute(config_params_query):
874886
config_params_copy[row[0]] = row[1:]
875-
self.assertEqual(config_params_initial, config_params_copy)
887+
self.assertEqual(config_params_initial, config_params_copy, \
888+
"mismatch in pathman_config_params under the command: %s" % dump_restore_cmd)
876889

877890
# compare constraints on each partition
878891
constraints_query = """
@@ -885,7 +898,8 @@ def turnon_pathman(node):
885898
constraints_initial[row[0]] = row[1:]
886899
for row in con2.execute(constraints_query):
887900
constraints_copy[row[0]] = row[1:]
888-
self.assertEqual(constraints_initial, constraints_copy)
901+
self.assertEqual(constraints_initial, constraints_copy, \
902+
"mismatch in partitions' constraints under the command: %s" % dump_restore_cmd)
889903

890904
# clear copy database
891905
node.psql('copy', 'drop schema public cascade')

0 commit comments

Comments
 (0)