1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-15 01:04:37 +02:00

Add HRN_STORAGE_TIME() harness macro.

Makes updating the time of a path/file more streamlined in tests.

Also update all tests where utime() was being used directly.
This commit is contained in:
David Steele
2021-03-12 12:54:34 -05:00
parent 3c85a497a6
commit e07040c2e4
5 changed files with 34 additions and 23 deletions

View File

@ -5,6 +5,7 @@ Storage Test Harness
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <utime.h>
#include "common/crypto/cipherBlock.h" #include "common/crypto/cipherBlock.h"
#include "common/debug.h" #include "common/debug.h"
@ -310,3 +311,22 @@ hrnStoragePutLog(const Storage *storage, const char *file, const Buffer *buffer,
return strZ(log); return strZ(log);
} }
/**********************************************************************************************************************************/
void
hrnStorageTime(const int line, const Storage *const storage, const char *const path, const time_t modified)
{
hrnTestLogPrefix(line, true);
hrnTestResultBegin(__func__, line, false);
const char *const pathFull = strZ(storagePathP(storage, path == NULL ? NULL : STR(path)));
printf("time '%" PRId64 "' on '%s'\n", (int64_t)modified, pathFull);
fflush(stdout);
THROW_ON_SYS_ERROR_FMT(
utime(pathFull, &((struct utimbuf){.actime = modified, .modtime = modified})) == -1, FileInfoError,
"unable to set time for '%s'", pathFull);
hrnTestResultEnd();
}

View File

@ -99,6 +99,14 @@ Remove a file and error if it does not exist
TEST_RESULT_VOID(storageRemoveP(storage, STR(path), .errorOnMissing = true), "remove file '%s'", \ TEST_RESULT_VOID(storageRemoveP(storage, STR(path), .errorOnMissing = true), "remove file '%s'", \
strZ(storagePathP(storage, STR(path)))) strZ(storagePathP(storage, STR(path))))
/***********************************************************************************************************************************
Change the time of a path/file
***********************************************************************************************************************************/
#define HRN_STORAGE_TIME(storage, path, time) \
hrnStorageTime(__LINE__, storage, path, time)
void hrnStorageTime(const int line, const Storage *const storage, const char *const path, const time_t modified);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Dummy interface for constructing test storage drivers. All required functions are stubbed out so this interface can be copied and Dummy interface for constructing test storage drivers. All required functions are stubbed out so this interface can be copied and
specific functions replaced for testing. specific functions replaced for testing.

View File

@ -1,8 +1,6 @@
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Test Backup Command Test Backup Command
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include <utime.h>
#include "command/stanza/create.h" #include "command/stanza/create.h"
#include "command/stanza/upgrade.h" #include "command/stanza/upgrade.h"
#include "common/crypto/hash.h" #include "common/crypto/hash.h"
@ -2571,11 +2569,7 @@ testRun(void)
harnessCfgLoad(cfgCmdBackup, argList); harnessCfgLoad(cfgCmdBackup, argList);
// Update pg_control timestamp // Update pg_control timestamp
THROW_ON_SYS_ERROR( HRN_STORAGE_TIME(storagePg(), "global/pg_control", backupTimeStart);
utime(
strZ(storagePathP(storagePg(), STRDEF("global/pg_control"))),
&(struct utimbuf){.actime = backupTimeStart, .modtime = backupTimeStart}) != 0, FileWriteError,
"unable to set time");
// Run backup. Make sure that the timeline selected converts to hexdecimal that can't be interpreted as decimal. // 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); testBackupPqScriptP(PG_VERSION_11, backupTimeStart, .timeline = 0x2C);

View File

@ -1,9 +1,6 @@
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Test Posix Storage Test Posix Storage
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include <unistd.h>
#include <utime.h>
#include "common/io/io.h" #include "common/io/io.h"
#include "common/time.h" #include "common/time.h"
#include "storage/read.h" #include "storage/read.h"
@ -204,8 +201,7 @@ testRun(void)
"path not enforced"); "path not enforced");
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
struct utimbuf utimeTest = {.actime = 1000000000, .modtime = 1555160000}; HRN_STORAGE_TIME(storageTest, testPath(), 1555160000);
THROW_ON_SYS_ERROR_FMT(utime(testPath(), &utimeTest) != 0, FileWriteError, "unable to set time for '%s'", testPath());
TEST_ASSIGN(info, storageInfoP(storageTest, strNew(testPath())), "get path info"); TEST_ASSIGN(info, storageInfoP(storageTest, strNew(testPath())), "get path info");
TEST_RESULT_STR(info.name, NULL, " name is not set"); TEST_RESULT_STR(info.name, NULL, " name is not set");
@ -224,8 +220,7 @@ testRun(void)
const Buffer *buffer = BUFSTRDEF("TESTFILE"); const Buffer *buffer = BUFSTRDEF("TESTFILE");
TEST_RESULT_VOID(storagePutP(storageNewWriteP(storageTest, fileName), buffer), "put test file"); TEST_RESULT_VOID(storagePutP(storageNewWriteP(storageTest, fileName), buffer), "put test file");
utimeTest.modtime = 1555155555; HRN_STORAGE_TIME(storageTest, strZ(fileName), 1555155555);
THROW_ON_SYS_ERROR_FMT(utime(strZ(fileName), &utimeTest) != 0, FileWriteError, "unable to set time for '%s'", testPath());
#ifdef TEST_CONTAINER_REQUIRED #ifdef TEST_CONTAINER_REQUIRED
TEST_RESULT_INT(system(strZ(strNewFmt("sudo chown 99999:99999 %s", strZ(fileName)))), 0, "set invalid user/group"); TEST_RESULT_INT(system(strZ(strNewFmt("sudo chown 99999:99999 %s", strZ(fileName)))), 0, "set invalid user/group");

View File

@ -1,8 +1,6 @@
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Test Remote Storage Test Remote Storage
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include <utime.h>
#include "command/backup/pageChecksum.h" #include "command/backup/pageChecksum.h"
#include "common/crypto/cipherBlock.h" #include "common/crypto/cipherBlock.h"
#include "common/io/bufferRead.h" #include "common/io/bufferRead.h"
@ -98,9 +96,7 @@ testRun(void)
TEST_TITLE("path info"); TEST_TITLE("path info");
storagePathCreateP(storageTest, strNew("repo")); storagePathCreateP(storageTest, strNew("repo"));
struct utimbuf utimeTest = {.actime = 1000000000, .modtime = 1555160000}; HRN_STORAGE_TIME(storageTest, "repo", 1555160000);
THROW_ON_SYS_ERROR(
utime(strZ(storagePathP(storageTest, strNew("repo"))), &utimeTest) != 0, FileWriteError, "unable to set time");
StorageInfo info = {.exists = false}; StorageInfo info = {.exists = false};
TEST_ASSIGN(info, storageInfoP(storageRemote, NULL), "valid path"); TEST_ASSIGN(info, storageInfoP(storageRemote, NULL), "valid path");
@ -278,8 +274,7 @@ testRun(void)
storagePutP(storageNewWriteP(storageRemote, strNew("test"), .timeModified = 1555160001), BUFSTRDEF("TESTME")); storagePutP(storageNewWriteP(storageRemote, strNew("test"), .timeModified = 1555160001), BUFSTRDEF("TESTME"));
// Path timestamp must be set after file is created since file creation updates it // Path timestamp must be set after file is created since file creation updates it
struct utimbuf utimeTest = {.actime = 1000000000, .modtime = 1555160000}; HRN_STORAGE_TIME(storageRemote, NULL, 1555160000);
THROW_ON_SYS_ERROR(utime(strZ(storagePathP(storageRemote, NULL)), &utimeTest) != 0, FileWriteError, "unable to set time");
TEST_RESULT_BOOL( TEST_RESULT_BOOL(
storageInfoListP(storageRemote, NULL, hrnStorageInfoListCallback, &callbackData, .sortOrder = sortOrderAsc), storageInfoListP(storageRemote, NULL, hrnStorageInfoListCallback, &callbackData, .sortOrder = sortOrderAsc),
@ -298,8 +293,7 @@ testRun(void)
storageRemoveP(storageRemote, STRDEF("test"), .errorOnMissing = true); storageRemoveP(storageRemote, STRDEF("test"), .errorOnMissing = true);
// Path timestamp must be set after file is removed since file removal updates it // Path timestamp must be set after file is removed since file removal updates it
utimeTest = (struct utimbuf){.actime = 1000000000, .modtime = 1555160000}; HRN_STORAGE_TIME(storageRemote, NULL, 1555160000);
THROW_ON_SYS_ERROR(utime(strZ(storagePathP(storageRemote, NULL)), &utimeTest) != 0, FileWriteError, "unable to set time");
VariantList *paramList = varLstNew(); VariantList *paramList = varLstNew();
varLstAdd(paramList, varNewStrZ(hrnReplaceKey("{[path]}/repo"))); varLstAdd(paramList, varNewStrZ(hrnReplaceKey("{[path]}/repo")));