@@ -6,17 +6,24 @@ with import ../lib/testing.nix { inherit system pkgs; };
66with pkgs . lib ;
77
88let
9+ makePostgresqlWalReceiverTest = subTestName : postgresqlPackage : let
10+
911 postgresqlDataDir = "/var/db/postgresql/test" ;
1012 replicationUser = "wal_receiver_user" ;
1113 replicationSlot = "wal_receiver_slot" ;
1214 replicationConn = "postgresql://${ replicationUser } @localhost" ;
1315 baseBackupDir = "/tmp/pg_basebackup" ;
1416 walBackupDir = "/tmp/pg_wal" ;
15- recoveryConf = pkgs . writeText "recovery.conf" ''
17+ atLeast12 = versionAtLeast postgresqlPackage . version "12.0" ;
18+ restoreCommand = ''
1619 restore_command = 'cp ${ walBackupDir } /%f %p'
1720 '' ;
1821
19- makePostgresqlWalReceiverTest = subTestName : postgresqlPackage : makeTest {
22+ recoveryFile = if atLeast12
23+ then pkgs . writeTextDir "recovery.signal" ""
24+ else pkgs . writeTextDir "recovery.conf" "${ restoreCommand } " ;
25+
26+ in makeTest {
2027 name = "postgresql-wal-receiver-${ subTestName } " ;
2128 meta . maintainers = with maintainers ; [ pacien ] ;
2229
2936 wal_level = archive # alias for replica on pg >= 9.6
3037 max_wal_senders = 10
3138 max_replication_slots = 10
39+ '' + optionalString atLeast12 ''
40+ ${ restoreCommand }
41+ recovery_end_command = 'touch recovery.done'
3242 '' ;
3343 authentication = ''
3444 host replication ${ replicationUser } all trust
4555 slot = replicationSlot ;
4656 directory = walBackupDir ;
4757 } ;
58+ # This is only to speedup test, it isn't time racing. Service is set to autorestart always,
59+ # default 60sec is fine for real system, but is too much for a test
60+ systemd . services . postgresql-wal-receiver-main . serviceConfig . RestartSec = mkForce 5 ;
4861 } ;
4962
5063 testScript = ''
7083 # prepare WAL and recovery
7184 $machine->succeed('chmod a+rX -R ${ walBackupDir } ');
7285 $machine->execute('for part in ${ walBackupDir } /*.partial; do mv $part '' ${part%%.*}; done'); # make use of partial segments too
73- $machine->succeed('cp ${ recoveryConf } ${ postgresqlDataDir } /recovery.conf && chmod 666 ${ postgresqlDataDir } /recovery.conf ');
86+ $machine->succeed('cp ${ recoveryFile } /* ${ postgresqlDataDir } / && chmod 666 ${ postgresqlDataDir } /recovery* ');
7487
7588 # replay WAL
7689 $machine->systemctl('start postgresql');
0 commit comments