55import subprocess
66from sys import exit
77from time import sleep
8+ from shutil import copyfile
89
910
1011module_name = 'archive'
@@ -39,8 +40,7 @@ def test_pgpro434_1(self):
3940
4041 result = node .safe_psql ("postgres" , "SELECT * FROM t_heap" )
4142 self .backup_node (
42- backup_dir , 'node' , node ,
43- options = ["--log-level-file=verbose" ])
43+ backup_dir , 'node' , node )
4444 node .cleanup ()
4545
4646 self .restore_node (
@@ -53,8 +53,7 @@ def test_pgpro434_1(self):
5353
5454 # Make backup
5555 self .backup_node (
56- backup_dir , 'node' , node ,
57- options = ["--log-level-file=verbose" ])
56+ backup_dir , 'node' , node )
5857 node .cleanup ()
5958
6059 # Restore Database
@@ -253,7 +252,6 @@ def test_pgpro434_3(self):
253252 backup_dir , 'node' , node ,
254253 options = [
255254 "--archive-timeout=60" ,
256- "--log-level-file=verbose" ,
257255 "--stream" ]
258256 )
259257 # we should die here because exception is what we expect to happen
@@ -402,7 +400,7 @@ def test_arhive_push_file_exists_overwrite(self):
402400 self .del_test_dir (module_name , fname )
403401
404402 # @unittest.expectedFailure
405- # @unittest.skip("skip")
403+ @unittest .skip ("skip" )
406404 def test_replica_archive (self ):
407405 """
408406 make node without archiving, take stream backup and
@@ -417,7 +415,7 @@ def test_replica_archive(self):
417415 initdb_params = ['--data-checksums' ],
418416 pg_options = {
419417 'max_wal_senders' : '2' ,
420- 'checkpoint_timeout ' : '30s ' ,
418+ 'archive_timeout ' : '10s ' ,
421419 'max_wal_size' : '1GB' }
422420 )
423421 self .init_pb (backup_dir )
@@ -433,7 +431,7 @@ def test_replica_archive(self):
433431 "postgres" ,
434432 "create table t_heap as select i as id, md5(i::text) as text, "
435433 "md5(repeat(i::text,10))::tsvector as tsvector "
436- "from generate_series(0,256 ) i" )
434+ "from generate_series(0,2560 ) i" )
437435
438436 self .backup_node (backup_dir , 'master' , master , options = ['--stream' ])
439437 before = master .safe_psql ("postgres" , "SELECT * FROM t_heap" )
@@ -459,17 +457,16 @@ def test_replica_archive(self):
459457 "md5(repeat(i::text,10))::tsvector as tsvector "
460458 "from generate_series(256,512) i" )
461459 before = master .safe_psql ("postgres" , "SELECT * FROM t_heap" )
462- # ADD INSTANCE 'REPLICA'
463-
464- sleep (1 )
465460
466461 backup_id = self .backup_node (
467462 backup_dir , 'replica' , replica ,
468463 options = [
469464 '--archive-timeout=30' ,
470465 '--master-host=localhost' ,
471466 '--master-db=postgres' ,
472- '--master-port={0}' .format (master .port )])
467+ '--master-port={0}' .format (master .port ),
468+ '--stream' ])
469+
473470 self .validate_pb (backup_dir , 'replica' )
474471 self .assertEqual (
475472 'OK' , self .show_pb (backup_dir , 'replica' , backup_id )['status' ])
@@ -493,16 +490,28 @@ def test_replica_archive(self):
493490 "postgres" ,
494491 "insert into t_heap as select i as id, md5(i::text) as text, "
495492 "md5(repeat(i::text,10))::tsvector as tsvector "
496- "from generate_series(512,768) i" )
493+ "from generate_series(512,20680) i" )
494+
497495 before = master .safe_psql ("postgres" , "SELECT * FROM t_heap" )
496+
497+ master .safe_psql (
498+ "postgres" ,
499+ "CHECKPOINT" )
500+
501+ # copyfile(
502+ # os.path.join(backup_dir, 'wal/master/000000010000000000000002'),
503+ # os.path.join(backup_dir, 'wal/replica/000000010000000000000002'))
504+
498505 backup_id = self .backup_node (
499506 backup_dir , 'replica' ,
500507 replica , backup_type = 'page' ,
501508 options = [
502- '--archive-timeout=30' , '--log-level-file=verbose' ,
503- '--master-host=localhost' , '--master-db=postgres' ,
504- '--master-port={0}' .format (master .port )]
505- )
509+ '--archive-timeout=30' ,
510+ '--master-db=postgres' ,
511+ '--master-host=localhost' ,
512+ '--master-port={0}' .format (master .port ),
513+ '--stream' ])
514+
506515 self .validate_pb (backup_dir , 'replica' )
507516 self .assertEqual (
508517 'OK' , self .show_pb (backup_dir , 'replica' , backup_id )['status' ])
@@ -511,8 +520,10 @@ def test_replica_archive(self):
511520 node .cleanup ()
512521 self .restore_node (
513522 backup_dir , 'replica' , data_dir = node .data_dir , backup_id = backup_id )
523+
514524 node .append_conf (
515525 'postgresql.auto.conf' , 'port = {0}' .format (node .port ))
526+
516527 node .slow_start ()
517528 # CHECK DATA CORRECTNESS
518529 after = node .safe_psql ("postgres" , "SELECT * FROM t_heap" )
@@ -537,7 +548,7 @@ def test_master_and_replica_parallel_archiving(self):
537548 set_replication = True ,
538549 initdb_params = ['--data-checksums' ],
539550 pg_options = {
540- 'checkpoint_timeout ' : '30s ' }
551+ 'archive_timeout ' : '10s ' }
541552 )
542553 replica = self .make_simple_node (
543554 base_dir = "{0}/{1}/replica" .format (module_name , fname ))
@@ -568,7 +579,7 @@ def test_master_and_replica_parallel_archiving(self):
568579 pgdata_replica = self .pgdata_content (replica .data_dir )
569580 self .compare_pgdata (pgdata_master , pgdata_replica )
570581
571- self .set_replica (master , replica , synchronous = True )
582+ self .set_replica (master , replica )
572583 # ADD INSTANCE REPLICA
573584 self .add_instance (backup_dir , 'replica' , replica )
574585 # SET ARCHIVING FOR REPLICA
@@ -579,16 +590,26 @@ def test_master_and_replica_parallel_archiving(self):
579590 after = replica .safe_psql ("postgres" , "SELECT * FROM t_heap" )
580591 self .assertEqual (before , after )
581592
593+ master .psql (
594+ "postgres" ,
595+ "insert into t_heap select i as id, md5(i::text) as text, "
596+ "md5(repeat(i::text,10))::tsvector as tsvector "
597+ "from generate_series(0, 60000) i" )
598+
582599 # TAKE FULL ARCHIVE BACKUP FROM REPLICA
600+ copyfile (
601+ os .path .join (backup_dir , 'wal/master/000000010000000000000001' ),
602+ os .path .join (backup_dir , 'wal/replica/000000010000000000000001' ))
603+
583604 backup_id = self .backup_node (
584605 backup_dir , 'replica' , replica ,
585606 options = [
586- '--archive-timeout=20' ,
587- '--log-level-file=verbose' ,
607+ '--archive-timeout=30' ,
588608 '--master-host=localhost' ,
589609 '--master-db=postgres' ,
590- '--master-port={0}' .format (master .port )]
591- )
610+ '--master-port={0}' .format (master .port ),
611+ '--stream' ])
612+
592613 self .validate_pb (backup_dir , 'replica' )
593614 self .assertEqual (
594615 'OK' , self .show_pb (backup_dir , 'replica' , backup_id )['status' ])
@@ -618,7 +639,8 @@ def test_master_and_replica_concurrent_archiving(self):
618639 set_replication = True ,
619640 initdb_params = ['--data-checksums' ],
620641 pg_options = {
621- 'checkpoint_timeout' : '30s' }
642+ 'checkpoint_timeout' : '30s' ,
643+ 'archive_timeout' : '10s' }
622644 )
623645 replica = self .make_simple_node (
624646 base_dir = "{0}/{1}/replica" .format (module_name , fname ))
0 commit comments