You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-03 00:26:59 +02:00
Clear test directory between test runs.
Previously it was the responsibility of the individual tests to clean up after themselves. Now the test harness now does the cleanup automatically. This means that some paths/files need to be recreated with each run but that doesn't happen very often. An attempt has been made to remove all redundant cleanup code but it's hard to know if everything has been caught. No issues will be caused by anything that was missed, but they will continue to chew up time in the tests.
This commit is contained in:
@ -121,6 +121,10 @@
|
||||
<p>Make Valgrind return an error even when a non-fatal issue is detected. Update some minor issues discovered in the tests as a result.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Clear test directory between test runs.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Allow C or Perl coverage to run on more than one VM.</p>
|
||||
</release-item>
|
||||
|
@ -148,9 +148,22 @@ testBegin(const char *name)
|
||||
if (testList[testRun - 1].selected)
|
||||
{
|
||||
#ifndef NO_LOG
|
||||
// Make sure there is nothing untested left in the log
|
||||
if (!testFirst)
|
||||
{
|
||||
// Make sure there is nothing untested left in the log
|
||||
harnessLogFinal();
|
||||
|
||||
// Clear out the test directory so the next test starts clean
|
||||
char buffer[2048];
|
||||
snprintf(buffer, sizeof(buffer), "sudo rm -rf %s/" "*", testPath());
|
||||
|
||||
if (system(buffer) != 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: unable to clear test path '%s'\n", testPath());
|
||||
fflush(stderr);
|
||||
exit(255);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// No longer the first test
|
||||
testFirst = false;
|
||||
|
@ -101,8 +101,6 @@ testRun(void)
|
||||
TEST_ERROR(archiveAsyncStatus(archiveModePush, segment, true), AssertError, "message");
|
||||
|
||||
TEST_RESULT_BOOL(archiveAsyncStatus(archiveModePush, segment, false), false, "suppress error");
|
||||
|
||||
unlink(strPtr(storagePathNP(storageSpool(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.error", strPtr(segment)))));
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
|
@ -120,10 +120,6 @@ testRun(void)
|
||||
storagePutNP(storageNewWriteNP(storageTest, strNew("repo/archive/test1/10-4/00000009.history")), NULL);
|
||||
|
||||
TEST_RESULT_STR(strPtr(archiveGetCheck(strNew("00000009.history"))), "10-4/00000009.history", "history file found");
|
||||
|
||||
// Clear data
|
||||
storagePathRemoveP(storageTest, strNew("repo"), .recurse = true);
|
||||
storagePathRemoveP(storageTest, strNew("db"), .recurse = true);
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
@ -202,10 +198,6 @@ testRun(void)
|
||||
TEST_RESULT_INT(archiveGetFile(archiveFile, walDestination), 0, "WAL segment copied");
|
||||
TEST_RESULT_BOOL(storageExistsNP(storageTest, walDestination), true, " check exists");
|
||||
TEST_RESULT_INT(storageInfoNP(storageTest, walDestination).size, 16 * 1024 * 1024, " check size");
|
||||
|
||||
// Clear data
|
||||
storagePathRemoveP(storageTest, strNew("repo"), .recurse = true);
|
||||
storagePathRemoveP(storageTest, strNew("db"), .recurse = true);
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
@ -278,8 +270,6 @@ testRun(void)
|
||||
TEST_RESULT_STR(
|
||||
strPtr(strLstJoin(strLstSort(storageListNP(storageSpool(), strNew(STORAGE_SPOOL_ARCHIVE_IN)), sortOrderAsc), "|")),
|
||||
"000000010000000A00000FFE|000000010000000A00000FFF", "check queue");
|
||||
|
||||
storagePathRemoveP(storageSpoolWrite(), strNew(STORAGE_SPOOL_ARCHIVE_IN), .recurse = true);
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
|
@ -4,6 +4,16 @@ Test Storage File
|
||||
#include "common/io/io.h"
|
||||
#include "storage/storage.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macro to create a path and file that cannot be accessed
|
||||
***********************************************************************************************************************************/
|
||||
#define TEST_CREATE_NOPERM() \
|
||||
TEST_RESULT_INT( \
|
||||
system( \
|
||||
strPtr(strNewFmt("sudo mkdir -m 700 %s && sudo touch %s && sudo chmod 600 %s", strPtr(pathNoPerm), strPtr(fileNoPerm), \
|
||||
strPtr(fileNoPerm)))), \
|
||||
0, "create no perm path/file");
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Test Run
|
||||
***********************************************************************************************************************************/
|
||||
@ -17,19 +27,15 @@ testRun(void)
|
||||
storageDriverPosixNew(strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL));
|
||||
ioBufferSizeSet(2);
|
||||
|
||||
// Create a directory and file that cannot be accessed to test permissions errors
|
||||
// Directory and file that cannot be accessed to test permissions errors
|
||||
String *fileNoPerm = strNewFmt("%s/noperm/noperm", testPath());
|
||||
String *pathNoPerm = strPath(fileNoPerm);
|
||||
|
||||
TEST_RESULT_INT(
|
||||
system(
|
||||
strPtr(strNewFmt("sudo mkdir -m 700 %s && sudo touch %s && sudo chmod 600 %s", strPtr(pathNoPerm), strPtr(fileNoPerm),
|
||||
strPtr(fileNoPerm)))),
|
||||
0, "create no perm path/file");
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("storageDriverPosixFile*()"))
|
||||
{
|
||||
TEST_CREATE_NOPERM();
|
||||
|
||||
TEST_ERROR_FMT(
|
||||
storageDriverPosixFileOpen(pathNoPerm, O_RDONLY, 0, false, false, "test"), PathOpenError,
|
||||
"unable to open '%s' for test: [13] Permission denied", strPtr(pathNoPerm));
|
||||
@ -72,6 +78,7 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("StorageFileRead"))
|
||||
{
|
||||
TEST_CREATE_NOPERM();
|
||||
StorageFileRead *file = NULL;
|
||||
|
||||
TEST_ASSIGN(file, storageNewReadP(storageTest, fileNoPerm, .ignoreMissing = true), "new read file");
|
||||
@ -173,6 +180,7 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("StorageFileWrite"))
|
||||
{
|
||||
TEST_CREATE_NOPERM();
|
||||
StorageFileWrite *file = NULL;
|
||||
|
||||
TEST_ASSIGN(
|
||||
|
@ -24,6 +24,16 @@ storageTestPathExpression(const String *expression, const String *path)
|
||||
return result;
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macro to create a path and file that cannot be accessed
|
||||
***********************************************************************************************************************************/
|
||||
#define TEST_CREATE_NOPERM() \
|
||||
TEST_RESULT_INT( \
|
||||
system( \
|
||||
strPtr(strNewFmt("sudo mkdir -m 700 %s && sudo touch %s && sudo chmod 600 %s", strPtr(pathNoPerm), strPtr(fileNoPerm), \
|
||||
strPtr(fileNoPerm)))), \
|
||||
0, "create no perm path/file");
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Test Run
|
||||
***********************************************************************************************************************************/
|
||||
@ -39,16 +49,10 @@ testRun(void)
|
||||
storageDriverPosixNew(strNew("/tmp"), 0, 0, true, NULL));
|
||||
ioBufferSizeSet(2);
|
||||
|
||||
// Create a directory and file that cannot be accessed to test permissions errors
|
||||
// Directory and file that cannot be accessed to test permissions errors
|
||||
String *fileNoPerm = strNewFmt("%s/noperm/noperm", testPath());
|
||||
String *pathNoPerm = strPath(fileNoPerm);
|
||||
|
||||
TEST_RESULT_INT(
|
||||
system(
|
||||
strPtr(strNewFmt("sudo mkdir -m 700 %s && sudo touch %s && sudo chmod 600 %s", strPtr(pathNoPerm), strPtr(fileNoPerm),
|
||||
strPtr(fileNoPerm)))),
|
||||
0, "create no perm path/file");
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("storageNew() and storageFree()"))
|
||||
{
|
||||
@ -80,6 +84,8 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("storageExists()"))
|
||||
{
|
||||
TEST_CREATE_NOPERM();
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_BOOL(storageExistsNP(storageTest, strNew("missing")), false, "file does not exist");
|
||||
TEST_RESULT_BOOL(storageExistsP(storageTest, strNew("missing"), .timeout = .1), false, "file does not exist");
|
||||
@ -118,6 +124,8 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("storageInfo()"))
|
||||
{
|
||||
TEST_CREATE_NOPERM();
|
||||
|
||||
TEST_ERROR_FMT(
|
||||
storageInfoNP(storageTest, fileNoPerm), FileOpenError,
|
||||
"unable to get info for '%s': [13] Permission denied", strPtr(fileNoPerm));
|
||||
@ -177,6 +185,8 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("storageList()"))
|
||||
{
|
||||
TEST_CREATE_NOPERM();
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_ERROR_FMT(
|
||||
storageListP(storageTest, strNew(BOGUS_STR), .errorOnMissing = true), PathOpenError,
|
||||
@ -241,6 +251,8 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("storageMove()"))
|
||||
{
|
||||
TEST_CREATE_NOPERM();
|
||||
|
||||
String *sourceFile = strNewFmt("%s/source.txt", testPath());
|
||||
String *destinationFile = strNewFmt("%s/sub/destination.txt", testPath());
|
||||
|
||||
@ -448,6 +460,8 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("storagePathSync()"))
|
||||
{
|
||||
TEST_CREATE_NOPERM();
|
||||
|
||||
TEST_ERROR_FMT(
|
||||
storagePathSyncNP(storageTest, fileNoPerm), PathOpenError,
|
||||
"unable to open '%s' for sync: [13] Permission denied", strPtr(fileNoPerm));
|
||||
@ -492,6 +506,7 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("storageNewWrite()"))
|
||||
{
|
||||
TEST_CREATE_NOPERM();
|
||||
StorageFileWrite *file = NULL;
|
||||
|
||||
TEST_ASSIGN(file, storageNewWriteP(storageTest, fileNoPerm, .noAtomic = true), "new write file (defaults)");
|
||||
@ -581,6 +596,8 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("storageRemove()"))
|
||||
{
|
||||
TEST_CREATE_NOPERM();
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_VOID(storageRemoveNP(storageTest, strNew("missing")), "remove missing file");
|
||||
TEST_ERROR_FMT(
|
||||
|
Reference in New Issue
Block a user