Skip to content

Commit 3c00972

Browse files
committed
tests: move to python3
1 parent 842e6ce commit 3c00972

16 files changed

+123
-95
lines changed

tests/Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Run ptrack tests:
3434
3535
3636
Usage:
37-
pip install testgres==1.8.2
37+
pip install testgres
3838
export PG_CONFIG=/path/to/pg_config
3939
python -m unittest [-v] tests[.specific_module][.class.test]
4040
```

tests/archive.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def test_pgpro434_4(self):
316316
"postgres",
317317
"SELECT pid "
318318
"FROM pg_stat_activity "
319-
"WHERE application_name = 'pg_probackup'").rstrip()
319+
"WHERE application_name = 'pg_probackup'").decode('utf-8').rstrip()
320320

321321
os.environ["PGAPPNAME"] = "pg_probackup"
322322

@@ -371,7 +371,7 @@ def test_archive_push_file_exists(self):
371371
filename = '000000010000000000000001'
372372
file = os.path.join(wals_dir, filename)
373373

374-
with open(file, 'a') as f:
374+
with open(file, 'a+b') as f:
375375
f.write(b"blablablaadssaaaaaaaaaaaaaaa")
376376
f.flush()
377377
f.close()
@@ -458,7 +458,7 @@ def test_archive_push_file_exists_overwrite(self):
458458
filename = '000000010000000000000001'
459459
file = os.path.join(wals_dir, filename)
460460

461-
with open(file, 'a') as f:
461+
with open(file, 'a+b') as f:
462462
f.write(b"blablablaadssaaaaaaaaaaaaaaa")
463463
f.flush()
464464
f.close()
@@ -538,7 +538,7 @@ def test_archive_push_partial_file_exists(self):
538538

539539
xid = node.safe_psql(
540540
"postgres",
541-
"INSERT INTO t1 VALUES (1) RETURNING (xmin)").rstrip()
541+
"INSERT INTO t1 VALUES (1) RETURNING (xmin)").decode('utf-8').rstrip()
542542

543543
if self.get_version(node) < 100000:
544544
filename_orig = node.safe_psql(
@@ -551,6 +551,8 @@ def test_archive_push_partial_file_exists(self):
551551
"SELECT file_name "
552552
"FROM pg_walfile_name_offset(pg_current_wal_flush_lsn());").rstrip()
553553

554+
filename_orig = filename_orig.decode('utf-8')
555+
554556
# form up path to next .part WAL segment
555557
wals_dir = os.path.join(backup_dir, 'wal', 'node')
556558
if self.archive_compress:
@@ -561,7 +563,7 @@ def test_archive_push_partial_file_exists(self):
561563
file = os.path.join(wals_dir, filename)
562564

563565
# emulate stale .part file
564-
with open(file, 'a') as f:
566+
with open(file, 'a+b') as f:
565567
f.write(b"blahblah")
566568
f.flush()
567569
f.close()
@@ -628,6 +630,8 @@ def test_archive_push_part_file_exists_not_stale(self):
628630
"SELECT file_name "
629631
"FROM pg_walfile_name_offset(pg_current_wal_flush_lsn());").rstrip()
630632

633+
filename_orig = filename_orig.decode('utf-8')
634+
631635
# form up path to next .part WAL segment
632636
wals_dir = os.path.join(backup_dir, 'wal', 'node')
633637
if self.archive_compress:
@@ -637,15 +641,15 @@ def test_archive_push_part_file_exists_not_stale(self):
637641
filename = filename_orig + '.part'
638642
file = os.path.join(wals_dir, filename)
639643

640-
with open(file, 'a') as f:
644+
with open(file, 'a+b') as f:
641645
f.write(b"blahblah")
642646
f.flush()
643647
f.close()
644648

645649
self.switch_wal_segment(node)
646650
sleep(30)
647651

648-
with open(file, 'a') as f:
652+
with open(file, 'a+b') as f:
649653
f.write(b"blahblahblahblah")
650654
f.flush()
651655
f.close()
@@ -2378,6 +2382,8 @@ def test_archive_show_partial_files_handling(self):
23782382
"SELECT file_name "
23792383
"FROM pg_walfile_name_offset(pg_current_wal_flush_lsn())").rstrip()
23802384

2385+
filename = filename.decode('utf-8')
2386+
23812387
self.switch_wal_segment(node)
23822388

23832389
os.rename(
@@ -2400,6 +2406,8 @@ def test_archive_show_partial_files_handling(self):
24002406
"SELECT file_name "
24012407
"FROM pg_walfile_name_offset(pg_current_wal_flush_lsn())").rstrip()
24022408

2409+
filename = filename.decode('utf-8')
2410+
24032411
self.switch_wal_segment(node)
24042412

24052413
os.rename(
@@ -2422,6 +2430,8 @@ def test_archive_show_partial_files_handling(self):
24222430
"SELECT file_name "
24232431
"FROM pg_walfile_name_offset(pg_current_wal_flush_lsn())").rstrip()
24242432

2433+
filename = filename.decode('utf-8')
2434+
24252435
self.switch_wal_segment(node)
24262436

24272437
os.rename(
@@ -2444,6 +2454,8 @@ def test_archive_show_partial_files_handling(self):
24442454
"SELECT file_name "
24452455
"FROM pg_walfile_name_offset(pg_current_wal_flush_lsn())").rstrip()
24462456

2457+
filename = filename.decode('utf-8')
2458+
24472459
self.switch_wal_segment(node)
24482460

24492461
os.rename(

tests/backup.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def test_page_detect_corruption(self):
349349

350350
heap_path = node.safe_psql(
351351
"postgres",
352-
"select pg_relation_filepath('t_heap')").rstrip()
352+
"select pg_relation_filepath('t_heap')").decode('utf-8').rstrip()
353353

354354
path = os.path.join(node.data_dir, heap_path)
355355
with open(path, "rb+", 0) as f:
@@ -416,7 +416,7 @@ def test_backup_detect_corruption(self):
416416

417417
heap_path = node.safe_psql(
418418
"postgres",
419-
"select pg_relation_filepath('t_heap')").rstrip()
419+
"select pg_relation_filepath('t_heap')").decode('utf-8').rstrip()
420420

421421
self.backup_node(
422422
backup_dir, 'node', node,
@@ -558,7 +558,7 @@ def test_backup_detect_invalid_block_header(self):
558558

559559
heap_path = node.safe_psql(
560560
"postgres",
561-
"select pg_relation_filepath('t_heap')").rstrip()
561+
"select pg_relation_filepath('t_heap')").decode('utf-8').rstrip()
562562

563563
self.backup_node(
564564
backup_dir, 'node', node,
@@ -699,7 +699,7 @@ def test_backup_detect_missing_permissions(self):
699699

700700
heap_path = node.safe_psql(
701701
"postgres",
702-
"select pg_relation_filepath('t_heap')").rstrip()
702+
"select pg_relation_filepath('t_heap')").decode('utf-8').rstrip()
703703

704704
self.backup_node(
705705
backup_dir, 'node', node,
@@ -840,7 +840,7 @@ def test_backup_truncate_misaligned(self):
840840

841841
heap_path = node.safe_psql(
842842
"postgres",
843-
"select pg_relation_filepath('t_heap')").rstrip()
843+
"select pg_relation_filepath('t_heap')").decode('utf-8').rstrip()
844844

845845
heap_size = node.safe_psql(
846846
"postgres",
@@ -922,7 +922,7 @@ def test_tablespace_in_pgdata_pgpro_1376(self):
922922
relfilenode = node.safe_psql(
923923
"postgres",
924924
"select 't_heap1'::regclass::oid"
925-
).rstrip()
925+
).decode('utf-8').rstrip()
926926

927927
list = []
928928
for root, dirs, files in os.walk(os.path.join(
@@ -1205,11 +1205,11 @@ def test_drop_rel_during_full_backup(self):
12051205

12061206
relative_path_1 = node.safe_psql(
12071207
"postgres",
1208-
"select pg_relation_filepath('t_heap_1')").rstrip()
1208+
"select pg_relation_filepath('t_heap_1')").decode('utf-8').rstrip()
12091209

12101210
relative_path_2 = node.safe_psql(
12111211
"postgres",
1212-
"select pg_relation_filepath('t_heap_1')").rstrip()
1212+
"select pg_relation_filepath('t_heap_1')").decode('utf-8').rstrip()
12131213

12141214
absolute_path_1 = os.path.join(node.data_dir, relative_path_1)
12151215
absolute_path_2 = os.path.join(node.data_dir, relative_path_2)
@@ -1350,7 +1350,7 @@ def test_drop_rel_during_backup_delta(self):
13501350

13511351
relative_path = node.safe_psql(
13521352
"postgres",
1353-
"select pg_relation_filepath('t_heap')").rstrip()
1353+
"select pg_relation_filepath('t_heap')").decode('utf-8').rstrip()
13541354

13551355
absolute_path = os.path.join(node.data_dir, relative_path)
13561356

@@ -1418,7 +1418,7 @@ def test_drop_rel_during_backup_page(self):
14181418

14191419
relative_path = node.safe_psql(
14201420
"postgres",
1421-
"select pg_relation_filepath('t_heap')").rstrip()
1421+
"select pg_relation_filepath('t_heap')").decode('utf-8').rstrip()
14221422

14231423
absolute_path = os.path.join(node.data_dir, relative_path)
14241424

@@ -1443,6 +1443,7 @@ def test_drop_rel_during_backup_page(self):
14431443

14441444
# File removed, we can proceed with backup
14451445
gdb.continue_execution_until_exit()
1446+
gdb.kill()
14461447

14471448
pgdata = self.pgdata_content(node.data_dir)
14481449

@@ -1492,7 +1493,7 @@ def test_drop_rel_during_backup_ptrack(self):
14921493

14931494
relative_path = node.safe_psql(
14941495
"postgres",
1495-
"select pg_relation_filepath('t_heap')").rstrip()
1496+
"select pg_relation_filepath('t_heap')").decode('utf-8').rstrip()
14961497

14971498
absolute_path = os.path.join(node.data_dir, relative_path)
14981499

@@ -1637,6 +1638,7 @@ def test_backup_concurrent_drop_table(self):
16371638

16381639
gdb.remove_all_breakpoints()
16391640
gdb.continue_execution_until_exit()
1641+
gdb.kill()
16401642

16411643
show_backup = self.show_pb(backup_dir, 'node')[0]
16421644

@@ -1761,6 +1763,7 @@ def test_sigint_handling(self):
17611763

17621764
gdb._execute('signal SIGINT')
17631765
gdb.continue_execution_until_error()
1766+
gdb.kill()
17641767

17651768
backup_id = self.show_pb(backup_dir, 'node')[0]['id']
17661769

@@ -1901,7 +1904,7 @@ def test_basic_missing_file_permissions(self):
19011904

19021905
relative_path = node.safe_psql(
19031906
"postgres",
1904-
"select pg_relation_filepath('pg_class')").rstrip()
1907+
"select pg_relation_filepath('pg_class')").decode('utf-8').rstrip()
19051908

19061909
full_path = os.path.join(node.data_dir, relative_path)
19071910

tests/checkdb.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,13 @@ def test_basic_checkdb_amcheck_only_sanity(self):
259259
node.data_dir,
260260
node.safe_psql(
261261
"db1",
262-
"select pg_relation_filepath('pgbench_accounts_pkey')").rstrip())
262+
"select pg_relation_filepath('pgbench_accounts_pkey')").decode('utf-8').rstrip())
263263

264264
index_path_2 = os.path.join(
265265
node.data_dir,
266266
node.safe_psql(
267267
"db2",
268-
"select pg_relation_filepath('some_index')").rstrip())
268+
"select pg_relation_filepath('some_index')").decode('utf-8').rstrip())
269269

270270
try:
271271
self.checkdb_node(
@@ -376,7 +376,7 @@ def test_checkdb_block_validation_sanity(self):
376376

377377
heap_path = node.safe_psql(
378378
"postgres",
379-
"select pg_relation_filepath('t_heap')").rstrip()
379+
"select pg_relation_filepath('t_heap')").decode('utf-8').rstrip()
380380

381381
# sanity
382382
try:
@@ -473,14 +473,15 @@ def test_checkdb_sigint_handling(self):
473473
gdb = self.checkdb_node(
474474
backup_dir, 'node', gdb=True,
475475
options=[
476-
'-d', 'postgres', '-j', '4',
476+
'-d', 'postgres', '-j', '2',
477477
'--skip-block-validation',
478+
'--progress',
478479
'--amcheck', '-p', str(node.port)])
479480

480481
gdb.set_breakpoint('amcheck_one_index')
481482
gdb.run_until_break()
482483

483-
gdb.continue_execution_until_break(10)
484+
gdb.continue_execution_until_break(20)
484485
gdb.remove_all_breakpoints()
485486

486487
gdb._execute('signal SIGINT')

tests/delta.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def test_delta_vacuum_truncate_2(self):
206206
filepath = node.safe_psql(
207207
"postgres",
208208
"select pg_relation_filepath('t_heap')"
209-
).rstrip()
209+
).decode('utf-8').rstrip()
210210

211211
self.backup_node(backup_dir, 'node', node)
212212

@@ -708,7 +708,7 @@ def test_exists_in_previous_backup(self):
708708
node.safe_psql("postgres", "SELECT * FROM t_heap")
709709
filepath = node.safe_psql(
710710
"postgres",
711-
"SELECT pg_relation_filepath('t_heap')").rstrip()
711+
"SELECT pg_relation_filepath('t_heap')").decode('utf-8').rstrip()
712712
self.backup_node(
713713
backup_dir,
714714
'node',
@@ -1063,7 +1063,7 @@ def test_delta_nullified_heap_page_backup(self):
10631063

10641064
file_path = node.safe_psql(
10651065
"postgres",
1066-
"select pg_relation_filepath('pgbench_accounts')").rstrip()
1066+
"select pg_relation_filepath('pgbench_accounts')").decode('utf-8').rstrip()
10671067

10681068
node.safe_psql(
10691069
"postgres",

tests/exclude.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def test_exclude_log_dir(self):
227227

228228
log_dir = node.safe_psql(
229229
'postgres',
230-
'show log_directory').rstrip()
230+
'show log_directory').decode('utf-8').rstrip()
231231

232232
node.cleanup()
233233

@@ -264,7 +264,7 @@ def test_exclude_log_dir_1(self):
264264

265265
log_dir = node.safe_psql(
266266
'postgres',
267-
'show log_directory').rstrip()
267+
'show log_directory').decode('utf-8').rstrip()
268268

269269
self.backup_node(
270270
backup_dir, 'node', node,

0 commit comments

Comments
 (0)