You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-01 00:25:06 +02:00
Refactor command/expire unit test module.
Add titles and use a Buffer to store backup.info instead of a String.
This commit is contained in:
committed by
David Steele
parent
f9c86b11a5
commit
e170c53e7e
@ -600,6 +600,9 @@ unit:
|
||||
coverage:
|
||||
command/expire/expire: full
|
||||
|
||||
include:
|
||||
- info/infoBackup
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------------
|
||||
- name: help
|
||||
total: 4
|
||||
|
@ -1,6 +1,7 @@
|
||||
/***********************************************************************************************************************************
|
||||
Test Expire Command
|
||||
***********************************************************************************************************************************/
|
||||
#include "common/io/bufferRead.h"
|
||||
#include "storage/posix/storage.h"
|
||||
|
||||
#include "common/harnessConfig.h"
|
||||
@ -83,7 +84,8 @@ testRun(void)
|
||||
StringList *argListAvoidWarn = strLstDup(argListBase);
|
||||
strLstAddZ(argListAvoidWarn, "--repo1-retention-full=1"); // avoid warning
|
||||
|
||||
String *backupInfoBase = strNew(
|
||||
const Buffer *backupInfoBase = harnessInfoChecksumZ
|
||||
(
|
||||
"[backup:current]\n"
|
||||
"20181119-152138F={"
|
||||
"\"backrest-format\":5,\"backrest-version\":\"2.08dev\","
|
||||
@ -144,13 +146,17 @@ testRun(void)
|
||||
"\n"
|
||||
"[db:history]\n"
|
||||
"1={\"db-catalog-version\":201409291,\"db-control-version\":942,\"db-system-id\":6625592122879095702,"
|
||||
"\"db-version\":\"9.4\"}");
|
||||
"\"db-version\":\"9.4\"}"
|
||||
);
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("expireBackup()"))
|
||||
{
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("manifest file removal");
|
||||
|
||||
// Create backup.info
|
||||
storagePutP(storageNewWriteP(storageTest, backupInfoFileName), harnessInfoChecksum(backupInfoBase));
|
||||
TEST_RESULT_VOID(storagePutP(storageNewWriteP(storageTest, backupInfoFileName), backupInfoBase), "write backup.info");
|
||||
|
||||
InfoBackup *infoBackup = NULL;
|
||||
TEST_ASSIGN(infoBackup, infoBackupLoadFile(storageTest, backupInfoFileName, cipherTypeNone, NULL), "get backup.info");
|
||||
@ -199,10 +205,11 @@ testRun(void)
|
||||
if (testBegin("expireFullBackup()"))
|
||||
{
|
||||
// Create backup.info
|
||||
storagePutP(storageNewWriteP(storageTest, backupInfoFileName), harnessInfoChecksum(backupInfoBase));
|
||||
|
||||
InfoBackup *infoBackup = NULL;
|
||||
TEST_ASSIGN(infoBackup, infoBackupLoadFile(storageTest, backupInfoFileName, cipherTypeNone, NULL), "get backup.info");
|
||||
TEST_ASSIGN(infoBackup, infoBackupNewLoad(ioBufferReadNew(backupInfoBase)), "get backup.info");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("retention-full not set - nothing expired");
|
||||
|
||||
// Load Parameters
|
||||
StringList *argList = strLstDup(argListBase);
|
||||
@ -215,6 +222,8 @@ testRun(void)
|
||||
"set option 'repo1-retention-full' to the maximum.");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("retention-full set - full backup no dependencies expired");
|
||||
|
||||
strLstAddZ(argList, "--repo1-retention-full=2");
|
||||
harnessCfgLoad(cfgCmdExpire, argList);
|
||||
|
||||
@ -228,6 +237,8 @@ testRun(void)
|
||||
harnessLogResult("P00 INFO: expire full backup 20181119-152138F");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("retention-full set - full backup with dependencies expired");
|
||||
|
||||
argList = strLstDup(argListBase);
|
||||
strLstAddZ(argList, "--repo1-retention-full=1");
|
||||
harnessCfgLoad(cfgCmdExpire, argList);
|
||||
@ -242,6 +253,8 @@ testRun(void)
|
||||
"20181119-152800F_20181119-152155I");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("retention-full set - no backups expired");
|
||||
|
||||
TEST_RESULT_UINT(expireFullBackup(infoBackup), 0, "retention-full=1 - not enough backups to expire any");
|
||||
TEST_RESULT_STR_Z(
|
||||
strLstJoin(infoBackupDataLabelList(infoBackup, NULL), ", "), "20181119-152900F, 20181119-152900F_20181119-152600D",
|
||||
@ -252,10 +265,11 @@ testRun(void)
|
||||
if (testBegin("expireDiffBackup()"))
|
||||
{
|
||||
// Create backup.info
|
||||
storagePutP(storageNewWriteP(storageTest, backupInfoFileName), harnessInfoChecksum(backupInfoBase));
|
||||
|
||||
InfoBackup *infoBackup = NULL;
|
||||
TEST_ASSIGN(infoBackup, infoBackupLoadFile(storageTest, backupInfoFileName, cipherTypeNone, NULL), "get backup.info");
|
||||
TEST_ASSIGN(infoBackup, infoBackupNewLoad(ioBufferReadNew(backupInfoBase)), "get backup.info");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("retention-diff not set");
|
||||
|
||||
// Load Parameters
|
||||
StringList *argList = strLstDup(argListAvoidWarn);
|
||||
@ -265,6 +279,8 @@ testRun(void)
|
||||
TEST_RESULT_UINT(infoBackupDataTotal(infoBackup), 6, "current backups not expired");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("retention-diff set - nothing yet to expire");
|
||||
|
||||
// Add retention-diff
|
||||
StringList *argListTemp = strLstDup(argList);
|
||||
strLstAddZ(argListTemp, "--repo1-retention-diff=6");
|
||||
@ -274,10 +290,12 @@ testRun(void)
|
||||
TEST_RESULT_UINT(infoBackupDataTotal(infoBackup), 6, "current backups not expired");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("retention-diff set - diff and dependent incr expired");
|
||||
|
||||
strLstAddZ(argList, "--repo1-retention-diff=2");
|
||||
harnessCfgLoad(cfgCmdExpire, argList);
|
||||
|
||||
TEST_RESULT_UINT(expireDiffBackup(infoBackup), 2, "retention-diff set - full considered in diff");
|
||||
TEST_RESULT_UINT(expireDiffBackup(infoBackup), 2, "retention-diff=2 - full considered in diff");
|
||||
TEST_RESULT_UINT(infoBackupDataTotal(infoBackup), 4, "current backups reduced by 1 diff and dependent increment");
|
||||
TEST_RESULT_STR_Z(
|
||||
strLstJoin(infoBackupDataLabelList(infoBackup, NULL), ", "),
|
||||
@ -290,6 +308,8 @@ testRun(void)
|
||||
TEST_RESULT_UINT(infoBackupDataTotal(infoBackup), 4, "current backups not reduced");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("retention-diff set - diff with no dependents expired");
|
||||
|
||||
// Create backup.info with two diff - oldest to be expired - no "set:"
|
||||
storagePutP(
|
||||
storageNewWriteP(storageTest, backupInfoFileName),
|
||||
@ -349,6 +369,9 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("removeExpiredBackup()"))
|
||||
{
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("remove expired backup from disk - backup not in current backup");
|
||||
|
||||
// Create backup.info
|
||||
storagePutP(
|
||||
storageNewWriteP(storageTest, backupInfoFileName),
|
||||
@ -413,6 +436,8 @@ testRun(void)
|
||||
"remaining file/directories correct");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("remove expired backup from disk - no current backups");
|
||||
|
||||
// Create backup.info without current backups
|
||||
storagePutP(
|
||||
storageNewWriteP(storageTest, backupInfoFileName),
|
||||
@ -441,6 +466,9 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("removeExpiredArchive() & cmdExpire()"))
|
||||
{
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("retention-archive not set");
|
||||
|
||||
// Load Parameters
|
||||
StringList *argList = strLstDup(argListBase);
|
||||
harnessCfgLoad(cfgCmdExpire, argList);
|
||||
@ -471,6 +499,8 @@ testRun(void)
|
||||
"P00 INFO: option 'repo1-retention-archive' is not set - archive logs will not be expired");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("retention-archive set - no current backups");
|
||||
|
||||
// Set archive retention, archive retention type default but no current backups - code path test
|
||||
strLstAddZ(argList, "--repo1-retention-archive=4");
|
||||
harnessCfgLoad(cfgCmdExpire, argList);
|
||||
@ -482,6 +512,8 @@ testRun(void)
|
||||
"set option 'repo1-retention-full' to the maximum.");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("retention-archive set - no archive on disk");
|
||||
|
||||
// Create backup.info with current backups spread over different timelines
|
||||
storagePutP(storageNewWriteP(storageTest, backupInfoFileName),
|
||||
harnessInfoChecksumZ(
|
||||
@ -574,6 +606,8 @@ testRun(void)
|
||||
TEST_RESULT_VOID(removeExpiredArchive(infoBackup), "no archive on disk");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("retention-archive set - remove archives across timelines");
|
||||
|
||||
archiveGenerate(storageTest, archiveStanzaPath, 1, 10, "9.4-1", "0000000100000000");
|
||||
archiveGenerate(storageTest, archiveStanzaPath, 1, 10, "9.4-1", "0000000200000000");
|
||||
archiveGenerate(storageTest, archiveStanzaPath, 1, 10, "10-2", "0000000100000000");
|
||||
@ -599,6 +633,8 @@ testRun(void)
|
||||
"P00 INFO: full backup total < 4 - using oldest full backup for 10-2 archive retention");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("retention-archive set - latest archive not expired");
|
||||
|
||||
argList = strLstDup(argListAvoidWarn);
|
||||
strLstAddZ(argList, "--repo1-retention-archive=2");
|
||||
harnessCfgLoad(cfgCmdExpire, argList);
|
||||
@ -622,6 +658,8 @@ testRun(void)
|
||||
"none removed from 10-2/0000000100000000");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("retention-archive set to lowest - keep PITR for each archiveId");
|
||||
|
||||
argList = strLstDup(argListAvoidWarn);
|
||||
strLstAddZ(argList, "--repo1-retention-archive=1");
|
||||
harnessCfgLoad(cfgCmdExpire, argList);
|
||||
@ -644,6 +682,8 @@ testRun(void)
|
||||
archiveExpectList(3, 10, "0000000100000000"), "none removed from 10-2/0000000100000000");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("retention-archive, retention-archive-type=diff, retention-diff set");
|
||||
|
||||
argList = strLstDup(argListAvoidWarn);
|
||||
strLstAddZ(argList, "--repo1-retention-archive=2");
|
||||
strLstAddZ(argList, "--repo1-retention-archive-type=diff");
|
||||
@ -678,6 +718,8 @@ testRun(void)
|
||||
archiveExpectList(3, 10, "0000000100000000"), "none removed from 10-2/0000000100000000");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("retention-archive, retention-archive-type=incr");
|
||||
|
||||
argList = strLstDup(argListAvoidWarn);
|
||||
strLstAddZ(argList, "--repo1-retention-archive=4");
|
||||
strLstAddZ(argList, "--repo1-retention-archive-type=incr");
|
||||
@ -711,6 +753,8 @@ testRun(void)
|
||||
archiveExpectList(3, 10, "0000000100000000"), "none removed from 10-2/0000000100000000");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("expire command - dry run");
|
||||
|
||||
argList = strLstDup(argListBase);
|
||||
strLstAddZ(argList, "--repo1-retention-full=2");
|
||||
strLstAddZ(argList, "--repo1-retention-diff=3");
|
||||
@ -762,6 +806,8 @@ testRun(void)
|
||||
storageNewWriteP(storageTest, strNewFmt("%s%s", strPtr(archiveInfoFileName), ".save")));
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("expire via backup command");
|
||||
|
||||
argList = strLstDup(argListBase);
|
||||
strLstAddZ(argList, "--repo1-retention-full=2");
|
||||
strLstAddZ(argList, "--repo1-retention-diff=3");
|
||||
@ -779,6 +825,8 @@ testRun(void)
|
||||
"P00 INFO: remove expired backup 20181119-152138F");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("expire command - no dry run");
|
||||
|
||||
argList = strLstDup(argListBase);
|
||||
strLstAddZ(argList, "--repo1-retention-full=2");
|
||||
strLstAddZ(argList, "--repo1-retention-diff=3");
|
||||
@ -809,6 +857,8 @@ testRun(void)
|
||||
"P00 INFO: remove expired backup 20181119-152138F");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("expire command - dry run: archive and backups not removed");
|
||||
|
||||
argList = strLstDup(argListAvoidWarn);
|
||||
strLstAddZ(argList, "--repo1-retention-archive=1");
|
||||
strLstAddZ(argList, "--dry-run");
|
||||
@ -836,6 +886,9 @@ testRun(void)
|
||||
"P00 INFO: [DRY-RUN] remove expired backup 20181119-152800F\n"
|
||||
"P00 INFO: [DRY-RUN] remove archive path: %s/%s/9.4-1", testPath(), strPtr(archiveStanzaPath))));
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("expire via backup command - archive and backups removed");
|
||||
|
||||
argList = strLstDup(argListAvoidWarn);
|
||||
strLstAddZ(argList, "--repo1-retention-archive=1");
|
||||
strLstAdd(argList, strNewFmt("--pg1-path=%s/pg", testPath()));
|
||||
@ -861,6 +914,9 @@ testRun(void)
|
||||
strLstJoin(strLstSort(infoBackupDataLabelList(infoBackup, NULL), sortOrderAsc), ", "),
|
||||
"20181119-152900F, 20181119-152900F_20181119-152500I", "remaining current backups correct");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("expire command - archive removed");
|
||||
|
||||
archiveGenerate(storageTest, archiveStanzaPath, 1, 1, "9.4-1", "0000000100000000");
|
||||
argList = strLstDup(argListAvoidWarn);
|
||||
strLstAddZ(argList, "--repo1-retention-archive=1");
|
||||
@ -915,6 +971,9 @@ testRun(void)
|
||||
|
||||
archiveGenerate(storageTest, archiveStanzaPath, 1, 5, "9.4-1", "0000000100000000");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("retention backup no archive-start");
|
||||
|
||||
argList = strLstDup(argListAvoidWarn);
|
||||
strLstAddZ(argList, "--repo1-retention-archive=2");
|
||||
strLstAddZ(argList, "--repo1-retention-archive-type=full");
|
||||
@ -927,6 +986,9 @@ testRun(void)
|
||||
storageTest, strNewFmt("%s/%s/%s", strPtr(archiveStanzaPath), "9.4-1", "0000000100000000")), sortOrderAsc), ", "),
|
||||
archiveExpectList(1, 5, "0000000100000000"), "nothing removed from 9.4-1/0000000100000000");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("retention-archive-type=incr");
|
||||
|
||||
argList = strLstDup(argListAvoidWarn);
|
||||
strLstAddZ(argList, "--repo1-retention-archive=4");
|
||||
strLstAddZ(argList, "--repo1-retention-archive-type=incr");
|
||||
@ -941,6 +1003,9 @@ testRun(void)
|
||||
harnessLogResult(
|
||||
"P00 INFO: full backup total < 4 - using oldest full backup for 9.4-1 archive retention");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("prior backup has no archive-start");
|
||||
|
||||
argList = strLstDup(argListAvoidWarn);
|
||||
strLstAddZ(argList, "--repo1-retention-archive=1");
|
||||
strLstAddZ(argList, "--repo1-retention-archive-type=full");
|
||||
@ -960,13 +1025,14 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("info files mismatch"))
|
||||
{
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("archive.info has only current db with different db history id as backup.info");
|
||||
|
||||
// Load Parameters
|
||||
StringList *argList = strLstDup(argListBase);
|
||||
strLstAddZ(argList, "--repo1-retention-full=2");
|
||||
harnessCfgLoad(cfgCmdExpire, argList);
|
||||
|
||||
// archive.info has only current db with different db history id as backup.info
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
storagePutP(storageNewWriteP(storageTest, backupInfoFileName),
|
||||
harnessInfoChecksumZ(
|
||||
"[backup:current]\n"
|
||||
@ -1049,8 +1115,9 @@ testRun(void)
|
||||
storageTest, strNewFmt("%s/%s/%s", strPtr(archiveStanzaPath), "10-2", "0000000100000000")), sortOrderAsc), ", "),
|
||||
archiveExpectList(1, 7, "0000000100000000"), "none removed from 10-2/0000000100000000");
|
||||
|
||||
// archive.info old history db system id not the same as backup.info
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("archive.info old history db system id not the same as backup.info");
|
||||
|
||||
storagePutP(
|
||||
storageNewWriteP(storageTest, archiveInfoFileName),
|
||||
harnessInfoChecksumZ(
|
||||
@ -1065,8 +1132,9 @@ testRun(void)
|
||||
|
||||
TEST_ERROR(cmdExpire(), FormatError, "archive expiration cannot continue - archive and backup history lists do not match");
|
||||
|
||||
// archive.info old history db version not the same as backup.info
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("archive.info old history db version not the same as backup.info");
|
||||
|
||||
storagePutP(
|
||||
storageNewWriteP(storageTest, archiveInfoFileName),
|
||||
harnessInfoChecksumZ(
|
||||
@ -1081,8 +1149,9 @@ testRun(void)
|
||||
|
||||
TEST_ERROR(cmdExpire(), FormatError, "archive expiration cannot continue - archive and backup history lists do not match");
|
||||
|
||||
// archive.info has only current db with same db history id as backup.info
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("archive.info has only current db with same db history id as backup.info");
|
||||
|
||||
storagePutP(storageNewWriteP(storageTest, backupInfoFileName),
|
||||
harnessInfoChecksumZ(
|
||||
"[backup:current]\n"
|
||||
@ -1175,6 +1244,9 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("archiveIdComparator()"))
|
||||
{
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("archiveId comparator sorting");
|
||||
|
||||
StringList *list = strLstNewParam(archiveIdComparator);
|
||||
|
||||
strLstAddZ(list, "10-4");
|
||||
|
Reference in New Issue
Block a user