From c6a8528e3158de3e4ccdba00c7af6d47cc28d073 Mon Sep 17 00:00:00 2001 From: David Steele Date: Tue, 8 Jun 2021 14:51:23 -0400 Subject: [PATCH] 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. --- test/src/common/harnessStorage.c | 7 +++- test/src/common/harnessStorage.h | 14 ++++--- test/src/module/command/archiveGetTest.c | 49 ++++++++++++++--------- test/src/module/command/archivePushTest.c | 25 +++++++----- test/src/module/command/backupTest.c | 6 +-- test/src/module/command/expireTest.c | 2 +- 6 files changed, 61 insertions(+), 42 deletions(-) diff --git a/test/src/common/harnessStorage.c b/test/src/common/harnessStorage.c index 05134ffd3..e0349b094 100644 --- a/test/src/common/harnessStorage.c +++ b/test/src/common/harnessStorage.c @@ -208,6 +208,9 @@ testStorageExists(const Storage *const storage, const char *const file, const Te hrnTestResultComment(param.comment); 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 -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); @@ -439,7 +442,7 @@ hrnStorageRemove(const Storage *const storage, const char *const file, const Tes printf("remove file '%s'", strZ(storagePathP(storage, STR(file)))); hrnTestResultComment(param.comment); - storageRemoveP(storage, STR(file), .errorOnMissing = true); + storageRemoveP(storage, STR(file), .errorOnMissing = param.errorOnMissing); hrnTestResultEnd(); } diff --git a/test/src/common/harnessStorage.h b/test/src/common/harnessStorage.h index 70f71d9ec..da7a61dd4 100644 --- a/test/src/common/harnessStorage.h +++ b/test/src/common/harnessStorage.h @@ -40,6 +40,7 @@ Check file exists typedef struct TestStorageExistsParam { VAR_PARAM_HEADER; + bool remove; // Remove file after testing? const char *comment; // Comment } TestStorageExistsParam; @@ -171,23 +172,24 @@ void hrnStoragePut( HrnStoragePutParam param); /*********************************************************************************************************************************** -Remove a file and error if it does not exist +Remove a file ***********************************************************************************************************************************/ -typedef struct TestStorageRemoveParam +typedef struct HrnStorageRemoveParam { VAR_PARAM_HEADER; + bool errorOnMissing; // Error when the file is missing const char *comment; // Comment -} TestStorageRemoveParam; +} HrnStorageRemoveParam; -#define TEST_STORAGE_REMOVE(storage, file, ...) \ +#define HRN_STORAGE_REMOVE(storage, file, ...) \ do \ { \ hrnTestLogPrefix(__LINE__); \ - hrnStorageRemove(storage, file, (TestStorageRemoveParam){VAR_PARAM_INIT, __VA_ARGS__}); \ + hrnStorageRemove(storage, file, (HrnStorageRemoveParam){VAR_PARAM_INIT, __VA_ARGS__}); \ } \ 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 diff --git a/test/src/module/command/archiveGetTest.c b/test/src/module/command/archiveGetTest.c index 84774bbd1..01c5aeb72 100644 --- a/test/src/module/command/archiveGetTest.c +++ b/test/src/module/command/archiveGetTest.c @@ -213,8 +213,9 @@ testRun(void) .remove = true); TEST_STORAGE_LIST(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN, "000000010000000100000001.pgbackrest.tmp\n"); - TEST_STORAGE_REMOVE( - storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz"); + TEST_STORAGE_EXISTS( + storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz", + .remove = true); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("single segment"); @@ -268,8 +269,9 @@ testRun(void) TEST_STORAGE_GET_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001", .remove = true); TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN); - TEST_STORAGE_REMOVE( - storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-2/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz"); + TEST_STORAGE_EXISTS( + storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-2/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz", + .remove = true); // ------------------------------------------------------------------------------------------------------------------------- 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_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN); - TEST_STORAGE_REMOVE( - storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-2/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz"); + TEST_STORAGE_EXISTS( + storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-2/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz", + .remove = true); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("multiple segments where some are missing or errored and mismatched repo"); @@ -442,10 +445,12 @@ testRun(void) .remove = true); TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN); - TEST_STORAGE_REMOVE( - storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); - TEST_STORAGE_REMOVE( - storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + TEST_STORAGE_EXISTS( + storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + .remove = true); + TEST_STORAGE_EXISTS( + storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + .remove = true); // ------------------------------------------------------------------------------------------------------------------------- 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_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN); - TEST_STORAGE_REMOVE( - storageRepoIdxWrite(1), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + TEST_STORAGE_EXISTS( + storageRepoIdxWrite(1), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + .remove = true); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("error with warnings"); @@ -837,8 +843,9 @@ testRun(void) "HINT: are multiple primaries archiving to this stanza?"); TEST_STORAGE_LIST(storagePg(), "pg_wal", NULL); - TEST_STORAGE_REMOVE( - storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); + TEST_STORAGE_EXISTS( + storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + .remove = true); // ------------------------------------------------------------------------------------------------------------------------- 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_STORAGE_LIST(storagePgWrite(), "pg_wal", "RECOVERYXLOG\n", .remove = true); - TEST_STORAGE_REMOVE( - storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); - TEST_STORAGE_REMOVE( - storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-4/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + TEST_STORAGE_EXISTS( + storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + .remove = true); + TEST_STORAGE_EXISTS( + storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-4/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + .remove = true); // ------------------------------------------------------------------------------------------------------------------------- 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_STORAGE_LIST(storagePgWrite(), "pg_wal", "RECOVERYXLOG\n", .remove = true); - TEST_STORAGE_REMOVE( + TEST_STORAGE_EXISTS( storageRepoWrite(), - STORAGE_REPO_ARCHIVE "/10-4/000000010000000100000001.partial-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + STORAGE_REPO_ARCHIVE "/10-4/000000010000000100000001.partial-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", .remove = true); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("get missing history"); diff --git a/test/src/module/command/archivePushTest.c b/test/src/module/command/archivePushTest.c index 98e1fabdf..4feab2291 100644 --- a/test/src/module/command/archivePushTest.c +++ b/test/src/module/command/archivePushTest.c @@ -342,8 +342,9 @@ testRun(void) storageRepoIdx(0), strNewFmt(STORAGE_REPO_ARCHIVE "/11-1/000000010000000100000001-%s.gz", walBuffer1Sha1)), true, "check repo for WAL file"); - TEST_STORAGE_REMOVE( - storageRepoIdxWrite(0), strZ(strNewFmt(STORAGE_REPO_ARCHIVE "/11-1/000000010000000100000001-%s.gz", walBuffer1Sha1))); + TEST_STORAGE_EXISTS( + storageRepoIdxWrite(0), strZ(strNewFmt(STORAGE_REPO_ARCHIVE "/11-1/000000010000000100000001-%s.gz", walBuffer1Sha1)), + .remove = true); // 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_STORAGE_REMOVE( - storageTest, strZ(strNewFmt("repo2/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1))); - TEST_STORAGE_REMOVE( - storageTest, strZ(strNewFmt("repo3/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1))); + TEST_STORAGE_EXISTS( + storageTest, strZ(strNewFmt("repo2/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1)), + .remove = true); + TEST_STORAGE_EXISTS( + storageTest, strZ(strNewFmt("repo3/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1)), + .remove = true); HRN_STORAGE_MODE(storageTest, "repo2", .mode = 0200); 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."); // Make sure WAL got pushed to repo3 - TEST_STORAGE_REMOVE( - 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"); @@ -619,8 +623,9 @@ testRun(void) " [13] Permission denied"); // Make sure WAL got pushed to repo3 - TEST_STORAGE_REMOVE( - 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/archive/test/11-1"); } diff --git a/test/src/module/command/backupTest.c b/test/src/module/command/backupTest.c index 30b2e9048..0451ed8e4 100644 --- a/test/src/module/command/backupTest.c +++ b/test/src/module/command/backupTest.c @@ -2422,9 +2422,9 @@ testRun(void) "compare file list"); // Remove test files - TEST_STORAGE_REMOVE(storagePgWrite(), "base/1/2"); - TEST_STORAGE_REMOVE(storagePgWrite(), "base/1/3"); - TEST_STORAGE_REMOVE(storagePgWrite(), "base/1/4"); + HRN_STORAGE_REMOVE(storagePgWrite(), "base/1/2", .errorOnMissing = true); + HRN_STORAGE_REMOVE(storagePgWrite(), "base/1/3", .errorOnMissing = true); + HRN_STORAGE_REMOVE(storagePgWrite(), "base/1/4", .errorOnMissing = true); } // ------------------------------------------------------------------------------------------------------------------------- diff --git a/test/src/module/command/expireTest.c b/test/src/module/command/expireTest.c index 479acf556..599c1eb47 100644 --- a/test/src/module/command/expireTest.c +++ b/test/src/module/command/expireTest.c @@ -473,7 +473,7 @@ testRun(void) TEST_ERROR(cmdExpire(), StopError, "stop file exists for stanza db"); // 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");