1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-11 00:50:20 +02:00

Add optional remove to TEST_STORAGE_EXISTS().

This allows TEST_STORAGE_EXISTS() to be used in most cases where TEST_STORAGE_REMOVE() was used before.

Rename TEST_STORAGE_REMOVE() to HRN_STORAGE_REMOVE() now that is is no longer used as a test. Still allow an error when the file is missing just to help keep tests tidy.
This commit is contained in:
David Steele
2021-06-08 14:51:23 -04:00
parent 4a075b7252
commit c6a8528e31
6 changed files with 61 additions and 42 deletions

View File

@ -208,6 +208,9 @@ testStorageExists(const Storage *const storage, const char *const file, const Te
hrnTestResultComment(param.comment); hrnTestResultComment(param.comment);
hrnTestResultBool(storageExistsP(storage, fileFull), true); hrnTestResultBool(storageExistsP(storage, fileFull), true);
if (param.remove)
storageRemoveP(storage, fileFull, .errorOnMissing = true);
} }
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
@ -429,7 +432,7 @@ hrnStoragePathRemove(const Storage *const storage, const char *const path, HrnSt
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
void void
hrnStorageRemove(const Storage *const storage, const char *const file, const TestStorageRemoveParam param) hrnStorageRemove(const Storage *const storage, const char *const file, const HrnStorageRemoveParam param)
{ {
hrnTestResultBegin(__func__, false); hrnTestResultBegin(__func__, false);
@ -439,7 +442,7 @@ hrnStorageRemove(const Storage *const storage, const char *const file, const Tes
printf("remove file '%s'", strZ(storagePathP(storage, STR(file)))); printf("remove file '%s'", strZ(storagePathP(storage, STR(file))));
hrnTestResultComment(param.comment); hrnTestResultComment(param.comment);
storageRemoveP(storage, STR(file), .errorOnMissing = true); storageRemoveP(storage, STR(file), .errorOnMissing = param.errorOnMissing);
hrnTestResultEnd(); hrnTestResultEnd();
} }

View File

@ -40,6 +40,7 @@ Check file exists
typedef struct TestStorageExistsParam typedef struct TestStorageExistsParam
{ {
VAR_PARAM_HEADER; VAR_PARAM_HEADER;
bool remove; // Remove file after testing?
const char *comment; // Comment const char *comment; // Comment
} TestStorageExistsParam; } TestStorageExistsParam;
@ -171,23 +172,24 @@ void hrnStoragePut(
HrnStoragePutParam param); HrnStoragePutParam param);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Remove a file and error if it does not exist Remove a file
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
typedef struct TestStorageRemoveParam typedef struct HrnStorageRemoveParam
{ {
VAR_PARAM_HEADER; VAR_PARAM_HEADER;
bool errorOnMissing; // Error when the file is missing
const char *comment; // Comment const char *comment; // Comment
} TestStorageRemoveParam; } HrnStorageRemoveParam;
#define TEST_STORAGE_REMOVE(storage, file, ...) \ #define HRN_STORAGE_REMOVE(storage, file, ...) \
do \ do \
{ \ { \
hrnTestLogPrefix(__LINE__); \ hrnTestLogPrefix(__LINE__); \
hrnStorageRemove(storage, file, (TestStorageRemoveParam){VAR_PARAM_INIT, __VA_ARGS__}); \ hrnStorageRemove(storage, file, (HrnStorageRemoveParam){VAR_PARAM_INIT, __VA_ARGS__}); \
} \ } \
while (0) while (0)
void hrnStorageRemove(const Storage *const storage, const char *const file, const TestStorageRemoveParam param); void hrnStorageRemove(const Storage *const storage, const char *const file, const HrnStorageRemoveParam param);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Change the time of a path/file Change the time of a path/file

View File

@ -213,8 +213,9 @@ testRun(void)
.remove = true); .remove = true);
TEST_STORAGE_LIST(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN, "000000010000000100000001.pgbackrest.tmp\n"); TEST_STORAGE_LIST(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN, "000000010000000100000001.pgbackrest.tmp\n");
TEST_STORAGE_REMOVE( TEST_STORAGE_EXISTS(
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz"); storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz",
.remove = true);
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("single segment"); TEST_TITLE("single segment");
@ -268,8 +269,9 @@ testRun(void)
TEST_STORAGE_GET_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001", .remove = true); TEST_STORAGE_GET_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001", .remove = true);
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN); TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
TEST_STORAGE_REMOVE( TEST_STORAGE_EXISTS(
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-2/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz"); storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-2/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz",
.remove = true);
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("single segment with one invalid file"); TEST_TITLE("single segment with one invalid file");
@ -305,8 +307,9 @@ testRun(void)
TEST_STORAGE_GET_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001", .remove = true); TEST_STORAGE_GET_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001", .remove = true);
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN); TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
TEST_STORAGE_REMOVE( TEST_STORAGE_EXISTS(
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-2/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz"); storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-2/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz",
.remove = true);
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("multiple segments where some are missing or errored and mismatched repo"); TEST_TITLE("multiple segments where some are missing or errored and mismatched repo");
@ -442,10 +445,12 @@ testRun(void)
.remove = true); .remove = true);
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN); TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
TEST_STORAGE_REMOVE( TEST_STORAGE_EXISTS(
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
TEST_STORAGE_REMOVE( .remove = true);
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); TEST_STORAGE_EXISTS(
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
.remove = true);
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("warn on invalid file"); TEST_TITLE("warn on invalid file");
@ -493,8 +498,9 @@ testRun(void)
TEST_STORAGE_GET_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000200000000", .remove = true); TEST_STORAGE_GET_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000200000000", .remove = true);
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN); TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
TEST_STORAGE_REMOVE( TEST_STORAGE_EXISTS(
storageRepoIdxWrite(1), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); storageRepoIdxWrite(1), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
.remove = true);
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("error with warnings"); TEST_TITLE("error with warnings");
@ -837,8 +843,9 @@ testRun(void)
"HINT: are multiple primaries archiving to this stanza?"); "HINT: are multiple primaries archiving to this stanza?");
TEST_STORAGE_LIST(storagePg(), "pg_wal", NULL); TEST_STORAGE_LIST(storagePg(), "pg_wal", NULL);
TEST_STORAGE_REMOVE( TEST_STORAGE_EXISTS(
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
.remove = true);
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("get from prior db-id"); TEST_TITLE("get from prior db-id");
@ -871,10 +878,12 @@ testRun(void)
TEST_RESULT_LOG("P00 INFO: found 01ABCDEF01ABCDEF01ABCDEF in the repo1: 10-4 archive"); TEST_RESULT_LOG("P00 INFO: found 01ABCDEF01ABCDEF01ABCDEF in the repo1: 10-4 archive");
TEST_STORAGE_LIST(storagePgWrite(), "pg_wal", "RECOVERYXLOG\n", .remove = true); TEST_STORAGE_LIST(storagePgWrite(), "pg_wal", "RECOVERYXLOG\n", .remove = true);
TEST_STORAGE_REMOVE( TEST_STORAGE_EXISTS(
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
TEST_STORAGE_REMOVE( .remove = true);
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-4/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); TEST_STORAGE_EXISTS(
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-4/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
.remove = true);
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("get partial"); TEST_TITLE("get partial");
@ -898,9 +907,9 @@ testRun(void)
TEST_RESULT_LOG("P00 INFO: found 000000010000000100000001.partial in the repo1: 10-4 archive"); TEST_RESULT_LOG("P00 INFO: found 000000010000000100000001.partial in the repo1: 10-4 archive");
TEST_STORAGE_LIST(storagePgWrite(), "pg_wal", "RECOVERYXLOG\n", .remove = true); TEST_STORAGE_LIST(storagePgWrite(), "pg_wal", "RECOVERYXLOG\n", .remove = true);
TEST_STORAGE_REMOVE( TEST_STORAGE_EXISTS(
storageRepoWrite(), storageRepoWrite(),
STORAGE_REPO_ARCHIVE "/10-4/000000010000000100000001.partial-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); STORAGE_REPO_ARCHIVE "/10-4/000000010000000100000001.partial-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", .remove = true);
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("get missing history"); TEST_TITLE("get missing history");

View File

@ -342,8 +342,9 @@ testRun(void)
storageRepoIdx(0), storageRepoIdx(0),
strNewFmt(STORAGE_REPO_ARCHIVE "/11-1/000000010000000100000001-%s.gz", walBuffer1Sha1)), strNewFmt(STORAGE_REPO_ARCHIVE "/11-1/000000010000000100000001-%s.gz", walBuffer1Sha1)),
true, "check repo for WAL file"); true, "check repo for WAL file");
TEST_STORAGE_REMOVE( TEST_STORAGE_EXISTS(
storageRepoIdxWrite(0), strZ(strNewFmt(STORAGE_REPO_ARCHIVE "/11-1/000000010000000100000001-%s.gz", walBuffer1Sha1))); storageRepoIdxWrite(0), strZ(strNewFmt(STORAGE_REPO_ARCHIVE "/11-1/000000010000000100000001-%s.gz", walBuffer1Sha1)),
.remove = true);
// Generate valid WAL and push them // Generate valid WAL and push them
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
@ -582,10 +583,12 @@ testRun(void)
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("push succeeds on one repo when other repo fails to load archive.info"); TEST_TITLE("push succeeds on one repo when other repo fails to load archive.info");
TEST_STORAGE_REMOVE( TEST_STORAGE_EXISTS(
storageTest, strZ(strNewFmt("repo2/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1))); storageTest, strZ(strNewFmt("repo2/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1)),
TEST_STORAGE_REMOVE( .remove = true);
storageTest, strZ(strNewFmt("repo3/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1))); TEST_STORAGE_EXISTS(
storageTest, strZ(strNewFmt("repo3/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1)),
.remove = true);
HRN_STORAGE_MODE(storageTest, "repo2", .mode = 0200); HRN_STORAGE_MODE(storageTest, "repo2", .mode = 0200);
TEST_ERROR( TEST_ERROR(
@ -602,8 +605,9 @@ testRun(void)
"HINT: use --no-archive-check to disable archive checks during backup if you have an alternate archiving scheme."); "HINT: use --no-archive-check to disable archive checks during backup if you have an alternate archiving scheme.");
// Make sure WAL got pushed to repo3 // Make sure WAL got pushed to repo3
TEST_STORAGE_REMOVE( TEST_STORAGE_EXISTS(
storageTest, strZ(strNewFmt("repo3/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1))); storageTest, strZ(strNewFmt("repo3/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1)),
.remove = true);
HRN_STORAGE_MODE(storageTest, "repo2"); HRN_STORAGE_MODE(storageTest, "repo2");
@ -619,8 +623,9 @@ testRun(void)
" [13] Permission denied"); " [13] Permission denied");
// Make sure WAL got pushed to repo3 // Make sure WAL got pushed to repo3
TEST_STORAGE_REMOVE( TEST_STORAGE_EXISTS(
storageTest, strZ(strNewFmt("repo3/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1))); storageTest, strZ(strNewFmt("repo3/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1)),
.remove = true);
HRN_STORAGE_MODE(storageTest, "repo2/archive/test/11-1"); HRN_STORAGE_MODE(storageTest, "repo2/archive/test/11-1");
} }

View File

@ -2422,9 +2422,9 @@ testRun(void)
"compare file list"); "compare file list");
// Remove test files // Remove test files
TEST_STORAGE_REMOVE(storagePgWrite(), "base/1/2"); HRN_STORAGE_REMOVE(storagePgWrite(), "base/1/2", .errorOnMissing = true);
TEST_STORAGE_REMOVE(storagePgWrite(), "base/1/3"); HRN_STORAGE_REMOVE(storagePgWrite(), "base/1/3", .errorOnMissing = true);
TEST_STORAGE_REMOVE(storagePgWrite(), "base/1/4"); HRN_STORAGE_REMOVE(storagePgWrite(), "base/1/4", .errorOnMissing = true);
} }
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------

View File

@ -473,7 +473,7 @@ testRun(void)
TEST_ERROR(cmdExpire(), StopError, "stop file exists for stanza db"); TEST_ERROR(cmdExpire(), StopError, "stop file exists for stanza db");
// Remove the stop file // Remove the stop file
TEST_STORAGE_REMOVE(storagePosixNewP(HRN_PATH_STR, .write = true), strZ(lockStopFileName(cfgOptionStr(cfgOptStanza)))); HRN_STORAGE_REMOVE(storagePosixNewP(HRN_PATH_STR, .write = true), strZ(lockStopFileName(cfgOptionStr(cfgOptStanza))));
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("retention-archive not set"); TEST_TITLE("retention-archive not set");