1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-30 05:39:12 +02:00

Add backup test harness.

This allows test backups to be run in other test modules.

It is likely that more logic will be moved here but for now this suffices to get test backups working in the restore module.
This commit is contained in:
David Steele 2022-12-05 14:15:15 +08:00
parent 96cf479d3c
commit 4dc632d570
4 changed files with 68 additions and 41 deletions

View File

@ -790,6 +790,7 @@ unit:
# ----------------------------------------------------------------------------------------------------------------------------
- name: backup
total: 11
harness: backup
coverage:
- command/backup/backup

View File

@ -0,0 +1,34 @@
/***********************************************************************************************************************************
Harness for Creating Test Backups
***********************************************************************************************************************************/
#include "build.auto.h"
#include <string.h>
#include "command/backup/backup.h"
#include "common/error.h"
#include "common/lock.h"
#include "config/config.h"
#include "common/harnessDebug.h"
#include "common/harnessTest.h"
/**********************************************************************************************************************************/
void hrnCmdBackup(void)
{
FUNCTION_HARNESS_VOID();
lockAcquire(STR(testPath()), cfgOptionStr(cfgOptStanza), cfgOptionStr(cfgOptExecId), lockTypeBackup, 0, true);
TRY_BEGIN()
{
cmdBackup();
}
FINALLY()
{
lockRelease(true);
}
TRY_END();
FUNCTION_HARNESS_RETURN_VOID();
}

View File

@ -0,0 +1,13 @@
/***********************************************************************************************************************************
Harness for Creating Test Backups
***********************************************************************************************************************************/
#ifndef TEST_COMMON_HARNESS_BACKUP_H
#define TEST_COMMON_HARNESS_BACKUP_H
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
// Create test backup and handle all the required locking. The backup configuration must already be loaded.
void hrnCmdBackup(void);
#endif

View File

@ -9,6 +9,7 @@ Test Backup Command
#include "storage/helper.h"
#include "storage/posix/storage.h"
#include "common/harnessBackup.h"
#include "common/harnessConfig.h"
#include "common/harnessPostgres.h"
#include "common/harnessPq.h"
@ -617,28 +618,6 @@ testBackupPqScript(unsigned int pgVersion, time_t backupTimeStart, TestBackupPqS
THROW_FMT(AssertError, "unsupported test version %u", pgVersion); // {uncoverable - no invalid versions in tests}
};
/***********************************************************************************************************************************
Wrap cmdBackup() with lock acquire and release
***********************************************************************************************************************************/
void testCmdBackup(void)
{
FUNCTION_HARNESS_VOID();
lockAcquire(TEST_PATH_STR, cfgOptionStr(cfgOptStanza), cfgOptionStr(cfgOptExecId), lockTypeBackup, 0, true);
TRY_BEGIN()
{
cmdBackup();
}
FINALLY()
{
lockRelease(true);
}
TRY_END();
FUNCTION_HARNESS_RETURN_VOID();
}
/***********************************************************************************************************************************
Test Run
***********************************************************************************************************************************/
@ -2003,7 +1982,7 @@ testRun(void)
HRN_STORAGE_PUT_Z(storagePgWrite(), PG_FILE_POSTMTRPID, "PID");
TEST_ERROR(
testCmdBackup(), PgRunningError,
hrnCmdBackup(), PgRunningError,
"--no-online passed but " PG_FILE_POSTMTRPID " exists - looks like " PG_NAME " is running. Shut down " PG_NAME " and"
" try again, or use --force.");
@ -2024,7 +2003,7 @@ testRun(void)
HRN_STORAGE_PUT_Z(storagePgWrite(), "postgresql.conf", "CONFIGSTUFF");
TEST_RESULT_VOID(testCmdBackup(), "backup");
TEST_RESULT_VOID(hrnCmdBackup(), "backup");
TEST_RESULT_LOG_FMT(
"P00 WARN: no prior backup exists, incr backup has been changed to full\n"
@ -2055,7 +2034,7 @@ testRun(void)
hrnCfgArgRawStrId(argList, cfgOptType, backupTypeDiff);
HRN_CFG_LOAD(cfgCmdBackup, argList);
TEST_ERROR(testCmdBackup(), FileMissingError, "no files have changed since the last backup - this seems unlikely");
TEST_ERROR(hrnCmdBackup(), FileMissingError, "no files have changed since the last backup - this seems unlikely");
TEST_RESULT_LOG(
"P00 INFO: last backup label = [FULL-1], version = " PROJECT_VERSION "\n"
@ -2077,7 +2056,7 @@ testRun(void)
HRN_STORAGE_PUT_Z(storagePgWrite(), PG_FILE_PGVERSION, "VER");
TEST_RESULT_VOID(testCmdBackup(), "backup");
TEST_RESULT_VOID(hrnCmdBackup(), "backup");
TEST_RESULT_LOG(
"P00 INFO: last backup label = [FULL-1], version = " PROJECT_VERSION "\n"
@ -2105,7 +2084,7 @@ testRun(void)
sleepMSec(MSEC_PER_SEC - (timeMSec() % MSEC_PER_SEC));
HRN_STORAGE_PUT_Z(storagePgWrite(), PG_FILE_PGVERSION, "VR2");
TEST_RESULT_VOID(testCmdBackup(), "backup");
TEST_RESULT_VOID(hrnCmdBackup(), "backup");
TEST_RESULT_LOG(
"P00 INFO: last backup label = [FULL-1], version = " PROJECT_VERSION "\n"
@ -2139,7 +2118,7 @@ testRun(void)
hrnCfgArgRawStrId(argList, cfgOptType, backupTypeDiff);
HRN_CFG_LOAD(cfgCmdBackup, argList);
TEST_RESULT_VOID(testCmdBackup(), "backup");
TEST_RESULT_VOID(hrnCmdBackup(), "backup");
TEST_RESULT_LOG("P00 WARN: no prior backup exists, diff backup has been changed to full");
@ -2154,7 +2133,7 @@ testRun(void)
hrnCfgArgKeyRawZ(argList, cfgOptRepoRetentionFull, 1, "1");
HRN_CFG_LOAD(cfgCmdBackup, argList);
TEST_RESULT_VOID(testCmdBackup(), "backup");
TEST_RESULT_VOID(hrnCmdBackup(), "backup");
TEST_RESULT_LOG(
"P00 INFO: repo option not specified, defaulting to repo1\n"
@ -2177,7 +2156,7 @@ testRun(void)
unsigned int backupCount = strLstSize(storageListP(storageRepoIdx(1), strNewFmt(STORAGE_PATH_BACKUP "/test1")));
TEST_RESULT_VOID(testCmdBackup(), "backup");
TEST_RESULT_VOID(hrnCmdBackup(), "backup");
TEST_RESULT_LOG(
"P00 INFO: last backup label = [FULL-2], version = " PROJECT_VERSION "\n"
@ -2288,7 +2267,7 @@ testRun(void)
// Run backup
testBackupPqScriptP(PG_VERSION_95, backupTimeStart, .noArchiveCheck = true, .noWal = true);
TEST_RESULT_VOID(testCmdBackup(), "backup");
TEST_RESULT_VOID(hrnCmdBackup(), "backup");
TEST_RESULT_LOG(
"P00 INFO: execute exclusive backup start: backup begins after the next regular checkpoint completes\n"
@ -2425,7 +2404,7 @@ testRun(void)
// Run backup
testBackupPqScriptP(PG_VERSION_95, backupTimeStart);
TEST_RESULT_VOID(testCmdBackup(), "backup");
TEST_RESULT_VOID(hrnCmdBackup(), "backup");
// Enable storage features
((Storage *)storageRepoWrite())->pub.interface.feature |= 1 << storageFeaturePath;
@ -2590,7 +2569,7 @@ testRun(void)
// Run backup
testBackupPqScriptP(PG_VERSION_95, backupTimeStart);
TEST_RESULT_VOID(testCmdBackup(), "backup");
TEST_RESULT_VOID(hrnCmdBackup(), "backup");
// Check log
TEST_RESULT_LOG(
@ -2730,7 +2709,7 @@ testRun(void)
testBackupPqScriptP(
PG_VERSION_96, backupTimeStart, .noPriorWal = true, .backupStandby = true, .walCompressType = compressTypeGz);
TEST_ERROR(
testCmdBackup(), ArchiveTimeoutError,
hrnCmdBackup(), ArchiveTimeoutError,
"WAL segment 0000000105DA69BF000000FF was not archived before the 100ms timeout\n"
"HINT: check the archive_command to ensure that all options are correct (especially --stanza).\n"
"HINT: check the PostgreSQL server log for errors.\n"
@ -2740,7 +2719,7 @@ testRun(void)
testBackupPqScriptP(
PG_VERSION_96, backupTimeStart, .noWal = true, .backupStandby = true, .walCompressType = compressTypeGz);
TEST_ERROR(
testCmdBackup(), ArchiveTimeoutError,
hrnCmdBackup(), ArchiveTimeoutError,
"WAL segment 0000000105DA69C000000000 was not archived before the 100ms timeout\n"
"HINT: check the archive_command to ensure that all options are correct (especially --stanza).\n"
"HINT: check the PostgreSQL server log for errors.\n"
@ -2759,7 +2738,7 @@ testRun(void)
// Run backup
testBackupPqScriptP(PG_VERSION_96, backupTimeStart, .backupStandby = true, .walCompressType = compressTypeGz);
TEST_RESULT_VOID(testCmdBackup(), "backup");
TEST_RESULT_VOID(hrnCmdBackup(), "backup");
// Check archive.info/copy timestamp was updated but contents were not
TEST_RESULT_INT_NE(
@ -2933,7 +2912,7 @@ testRun(void)
// Run backup
testBackupPqScriptP(PG_VERSION_11, backupTimeStart, .walCompressType = compressTypeGz, .walTotal = 3);
TEST_RESULT_VOID(testCmdBackup(), "backup");
TEST_RESULT_VOID(hrnCmdBackup(), "backup");
// Reset storage features
((Storage *)storageRepoWrite())->pub.interface.feature |= 1 << storageFeatureSymLink;
@ -3063,7 +3042,7 @@ testRun(void)
// Run backup
TEST_ERROR(
testCmdBackup(), FileMissingError,
hrnCmdBackup(), FileMissingError,
"pg_control must be present in all online backups\n"
"HINT: is something wrong with the clock or filesystem timestamps?");
@ -3101,7 +3080,7 @@ testRun(void)
// Run backup. Make sure that the timeline selected converts to hexdecimal that can't be interpreted as decimal.
testBackupPqScriptP(PG_VERSION_11, backupTimeStart, .timeline = 0x2C, .walTotal = 2);
TEST_RESULT_VOID(testCmdBackup(), "backup");
TEST_RESULT_VOID(hrnCmdBackup(), "backup");
TEST_RESULT_LOG(
"P00 INFO: last backup label = 20191027-181320F, version = " PROJECT_VERSION "\n"
@ -3234,7 +3213,7 @@ testRun(void)
// Run backup
testBackupPqScriptP(PG_VERSION_11, backupTimeStart, .walCompressType = compressTypeGz, .walTotal = 2);
TEST_RESULT_VOID(testCmdBackup(), "backup");
TEST_RESULT_VOID(hrnCmdBackup(), "backup");
TEST_RESULT_LOG(
"P00 INFO: execute non-exclusive backup start: backup begins after the next regular checkpoint completes\n"
@ -3364,7 +3343,7 @@ testRun(void)
// Run backup
testBackupPqScriptP(PG_VERSION_11, backupTimeStart, .walCompressType = compressTypeGz, .walTotal = 2);
TEST_RESULT_VOID(testCmdBackup(), "backup");
TEST_RESULT_VOID(hrnCmdBackup(), "backup");
TEST_RESULT_LOG(
"P00 INFO: last backup label = 20191030-014640F, version = " PROJECT_VERSION "\n"