Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit66ad282

Browse files
committed
tests: for ".partial" WAL file
1 parent68d6b3b commit66ad282

File tree

1 file changed

+189
-2
lines changed

1 file changed

+189
-2
lines changed

‎tests/archive.py‎

Lines changed: 189 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def test_pgpro434_1(self):
2525
set_replication=True,
2626
initdb_params=['--data-checksums'],
2727
pg_options={
28-
'checkpoint_timeout':'30s'}
29-
)
28+
'checkpoint_timeout':'30s'})
29+
3030
self.init_pb(backup_dir)
3131
self.add_instance(backup_dir,'node',node)
3232
self.set_archiving(backup_dir,'node',node)
@@ -411,6 +411,193 @@ def test_arhive_push_file_exists_overwrite(self):
411411
# Clean after yourself
412412
self.del_test_dir(module_name,fname)
413413

414+
# @unittest.skip("skip")
415+
deftest_arhive_push_partial_file_exists(self):
416+
"""Archive-push if file exists"""
417+
fname=self.id().split('.')[3]
418+
backup_dir=os.path.join(self.tmp_path,module_name,fname,'backup')
419+
node=self.make_simple_node(
420+
base_dir=os.path.join(module_name,fname,'node'),
421+
set_replication=True,
422+
initdb_params=['--data-checksums'])
423+
424+
self.init_pb(backup_dir)
425+
self.add_instance(backup_dir,'node',node)
426+
self.set_archiving(backup_dir,'node',node)
427+
428+
node.slow_start()
429+
node.safe_psql(
430+
"postgres",
431+
"create table t_heap as select i as id, md5(i::text) as text, "
432+
"md5(repeat(i::text,10))::tsvector as tsvector "
433+
"from generate_series(0,100500) i")
434+
435+
filename=node.safe_psql(
436+
"postgres",
437+
"SELECT file_name "
438+
"FROM pg_walfile_name_offset(pg_current_wal_flush_lsn());").rstrip()
439+
440+
wals_dir=os.path.join(backup_dir,'wal','node')
441+
ifself.archive_compress:
442+
filename=filename+'.gz'+'.partial'
443+
file=os.path.join(wals_dir,filename)
444+
else:
445+
filename=filename+'.partial'
446+
file=os.path.join(wals_dir,filename)
447+
448+
withopen(file,'a')asf:
449+
f.write(b"blablablaadssaaaaaaaaaaaaaaa")
450+
f.flush()
451+
f.close()
452+
453+
self.switch_wal_segment(node)
454+
sleep(15)
455+
456+
log_file=os.path.join(node.logs_dir,'postgresql.log')
457+
withopen(log_file,'r')asf:
458+
log_content=f.read()
459+
self.assertIn(
460+
'Reusing stale destination temporary WAL file',
461+
log_content)
462+
463+
# Clean after yourself
464+
self.del_test_dir(module_name,fname)
465+
466+
# @unittest.skip("skip")
467+
deftest_archive_push_partial_file_exists(self):
468+
"""Archive-push if file exists"""
469+
fname=self.id().split('.')[3]
470+
backup_dir=os.path.join(self.tmp_path,module_name,fname,'backup')
471+
node=self.make_simple_node(
472+
base_dir=os.path.join(module_name,fname,'node'),
473+
set_replication=True,
474+
initdb_params=['--data-checksums'])
475+
476+
self.init_pb(backup_dir)
477+
self.add_instance(backup_dir,'node',node)
478+
self.set_archiving(backup_dir,'node',node)
479+
480+
node.slow_start()
481+
482+
node.safe_psql(
483+
"postgres",
484+
"create table t1()")
485+
self.switch_wal_segment(node)
486+
487+
node.safe_psql(
488+
"postgres",
489+
"create table t2()")
490+
491+
filename_orig=node.safe_psql(
492+
"postgres",
493+
"SELECT file_name "
494+
"FROM pg_walfile_name_offset(pg_current_wal_flush_lsn());").rstrip()
495+
496+
wals_dir=os.path.join(backup_dir,'wal','node')
497+
ifself.archive_compress:
498+
filename=filename_orig+'.gz'+'.partial'
499+
file=os.path.join(wals_dir,filename)
500+
else:
501+
filename=filename_orig+'.partial'
502+
file=os.path.join(wals_dir,filename)
503+
504+
withopen(file,'a')asf:
505+
f.write(b"blablablaadssaaaaaaaaaaaaaaa")
506+
f.flush()
507+
f.close()
508+
509+
self.switch_wal_segment(node)
510+
sleep(15)
511+
512+
# check that segment is archived
513+
ifself.archive_compress:
514+
filename_orig=filename_orig+'.gz'
515+
516+
file=os.path.join(wals_dir,filename_orig)
517+
518+
self.assertTrue(os.path.isfile(file))
519+
520+
# log_file = os.path.join(node.logs_dir, 'postgresql.log')
521+
# with open(log_file, 'r') as f:
522+
# log_content = f.read()
523+
# self.assertIn(
524+
# 'Reusing stale destination temporary WAL file',
525+
# log_content)
526+
527+
# Clean after yourself
528+
self.del_test_dir(module_name,fname)
529+
530+
# @unittest.skip("skip")
531+
deftest_archive_push_partial_file_exists_not_stale(self):
532+
"""Archive-push if file exists"""
533+
fname=self.id().split('.')[3]
534+
backup_dir=os.path.join(self.tmp_path,module_name,fname,'backup')
535+
node=self.make_simple_node(
536+
base_dir=os.path.join(module_name,fname,'node'),
537+
set_replication=True,
538+
initdb_params=['--data-checksums'])
539+
540+
self.init_pb(backup_dir)
541+
self.add_instance(backup_dir,'node',node)
542+
self.set_archiving(backup_dir,'node',node)
543+
544+
node.slow_start()
545+
546+
node.safe_psql(
547+
"postgres",
548+
"create table t1()")
549+
self.switch_wal_segment(node)
550+
551+
node.safe_psql(
552+
"postgres",
553+
"create table t2()")
554+
555+
filename_orig=node.safe_psql(
556+
"postgres",
557+
"SELECT file_name "
558+
"FROM pg_walfile_name_offset(pg_current_wal_flush_lsn());").rstrip()
559+
560+
wals_dir=os.path.join(backup_dir,'wal','node')
561+
ifself.archive_compress:
562+
filename=filename_orig+'.gz'+'.partial'
563+
file=os.path.join(wals_dir,filename)
564+
else:
565+
filename=filename_orig+'.partial'
566+
file=os.path.join(wals_dir,filename)
567+
568+
withopen(file,'a')asf:
569+
f.write(b"blahblah")
570+
f.flush()
571+
f.close()
572+
573+
self.switch_wal_segment(node)
574+
sleep(4)
575+
576+
withopen(file,'a')asf:
577+
f.write(b"blahblahblahblah")
578+
f.flush()
579+
f.close()
580+
581+
sleep(10)
582+
583+
# check that segment is NOT archived
584+
ifself.archive_compress:
585+
filename_orig=filename_orig+'.gz'
586+
587+
file=os.path.join(wals_dir,filename_orig)
588+
589+
self.assertFalse(os.path.isfile(file))
590+
591+
# log_file = os.path.join(node.logs_dir, 'postgresql.log')
592+
# with open(log_file, 'r') as f:
593+
# log_content = f.read()
594+
# self.assertIn(
595+
# 'is not stale',
596+
# log_content)
597+
598+
# Clean after yourself
599+
self.del_test_dir(module_name,fname)
600+
414601
# @unittest.expectedFailure
415602
# @unittest.skip("skip")
416603
deftest_replica_archive(self):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp