1
0
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:
David Steele
2018-09-16 17:26:04 -04:00
parent 4119ce208d
commit a6c346cb04
6 changed files with 57 additions and 27 deletions

View File

@ -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> <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>
<release-item>
<p>Clear test directory between test runs.</p>
</release-item>
<release-item> <release-item>
<p>Allow C or Perl coverage to run on more than one VM.</p> <p>Allow C or Perl coverage to run on more than one VM.</p>
</release-item> </release-item>

View File

@ -148,9 +148,22 @@ testBegin(const char *name)
if (testList[testRun - 1].selected) if (testList[testRun - 1].selected)
{ {
#ifndef NO_LOG #ifndef NO_LOG
// Make sure there is nothing untested left in the log
if (!testFirst) if (!testFirst)
{
// Make sure there is nothing untested left in the log
harnessLogFinal(); 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 #endif
// No longer the first test // No longer the first test
testFirst = false; testFirst = false;

View File

@ -101,8 +101,6 @@ testRun(void)
TEST_ERROR(archiveAsyncStatus(archiveModePush, segment, true), AssertError, "message"); TEST_ERROR(archiveAsyncStatus(archiveModePush, segment, true), AssertError, "message");
TEST_RESULT_BOOL(archiveAsyncStatus(archiveModePush, segment, false), false, "suppress error"); TEST_RESULT_BOOL(archiveAsyncStatus(archiveModePush, segment, false), false, "suppress error");
unlink(strPtr(storagePathNP(storageSpool(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.error", strPtr(segment)))));
} }
// ***************************************************************************************************************************** // *****************************************************************************************************************************

View File

@ -120,10 +120,6 @@ testRun(void)
storagePutNP(storageNewWriteNP(storageTest, strNew("repo/archive/test1/10-4/00000009.history")), NULL); 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"); 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_INT(archiveGetFile(archiveFile, walDestination), 0, "WAL segment copied");
TEST_RESULT_BOOL(storageExistsNP(storageTest, walDestination), true, " check exists"); TEST_RESULT_BOOL(storageExistsNP(storageTest, walDestination), true, " check exists");
TEST_RESULT_INT(storageInfoNP(storageTest, walDestination).size, 16 * 1024 * 1024, " check size"); 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( TEST_RESULT_STR(
strPtr(strLstJoin(strLstSort(storageListNP(storageSpool(), strNew(STORAGE_SPOOL_ARCHIVE_IN)), sortOrderAsc), "|")), strPtr(strLstJoin(strLstSort(storageListNP(storageSpool(), strNew(STORAGE_SPOOL_ARCHIVE_IN)), sortOrderAsc), "|")),
"000000010000000A00000FFE|000000010000000A00000FFF", "check queue"); "000000010000000A00000FFE|000000010000000A00000FFF", "check queue");
storagePathRemoveP(storageSpoolWrite(), strNew(STORAGE_SPOOL_ARCHIVE_IN), .recurse = true);
} }
// ***************************************************************************************************************************** // *****************************************************************************************************************************

View File

@ -4,6 +4,16 @@ Test Storage File
#include "common/io/io.h" #include "common/io/io.h"
#include "storage/storage.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 Test Run
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
@ -17,19 +27,15 @@ testRun(void)
storageDriverPosixNew(strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL)); storageDriverPosixNew(strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL));
ioBufferSizeSet(2); 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 *fileNoPerm = strNewFmt("%s/noperm/noperm", testPath());
String *pathNoPerm = strPath(fileNoPerm); 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*()")) if (testBegin("storageDriverPosixFile*()"))
{ {
TEST_CREATE_NOPERM();
TEST_ERROR_FMT( TEST_ERROR_FMT(
storageDriverPosixFileOpen(pathNoPerm, O_RDONLY, 0, false, false, "test"), PathOpenError, storageDriverPosixFileOpen(pathNoPerm, O_RDONLY, 0, false, false, "test"), PathOpenError,
"unable to open '%s' for test: [13] Permission denied", strPtr(pathNoPerm)); "unable to open '%s' for test: [13] Permission denied", strPtr(pathNoPerm));
@ -72,6 +78,7 @@ testRun(void)
// ***************************************************************************************************************************** // *****************************************************************************************************************************
if (testBegin("StorageFileRead")) if (testBegin("StorageFileRead"))
{ {
TEST_CREATE_NOPERM();
StorageFileRead *file = NULL; StorageFileRead *file = NULL;
TEST_ASSIGN(file, storageNewReadP(storageTest, fileNoPerm, .ignoreMissing = true), "new read file"); TEST_ASSIGN(file, storageNewReadP(storageTest, fileNoPerm, .ignoreMissing = true), "new read file");
@ -173,6 +180,7 @@ testRun(void)
// ***************************************************************************************************************************** // *****************************************************************************************************************************
if (testBegin("StorageFileWrite")) if (testBegin("StorageFileWrite"))
{ {
TEST_CREATE_NOPERM();
StorageFileWrite *file = NULL; StorageFileWrite *file = NULL;
TEST_ASSIGN( TEST_ASSIGN(

View File

@ -24,6 +24,16 @@ storageTestPathExpression(const String *expression, const String *path)
return result; 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 Test Run
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
@ -39,16 +49,10 @@ testRun(void)
storageDriverPosixNew(strNew("/tmp"), 0, 0, true, NULL)); storageDriverPosixNew(strNew("/tmp"), 0, 0, true, NULL));
ioBufferSizeSet(2); 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 *fileNoPerm = strNewFmt("%s/noperm/noperm", testPath());
String *pathNoPerm = strPath(fileNoPerm); 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()")) if (testBegin("storageNew() and storageFree()"))
{ {
@ -80,6 +84,8 @@ testRun(void)
// ***************************************************************************************************************************** // *****************************************************************************************************************************
if (testBegin("storageExists()")) if (testBegin("storageExists()"))
{ {
TEST_CREATE_NOPERM();
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
TEST_RESULT_BOOL(storageExistsNP(storageTest, strNew("missing")), false, "file does not exist"); 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"); TEST_RESULT_BOOL(storageExistsP(storageTest, strNew("missing"), .timeout = .1), false, "file does not exist");
@ -118,6 +124,8 @@ testRun(void)
// ***************************************************************************************************************************** // *****************************************************************************************************************************
if (testBegin("storageInfo()")) if (testBegin("storageInfo()"))
{ {
TEST_CREATE_NOPERM();
TEST_ERROR_FMT( TEST_ERROR_FMT(
storageInfoNP(storageTest, fileNoPerm), FileOpenError, storageInfoNP(storageTest, fileNoPerm), FileOpenError,
"unable to get info for '%s': [13] Permission denied", strPtr(fileNoPerm)); "unable to get info for '%s': [13] Permission denied", strPtr(fileNoPerm));
@ -177,6 +185,8 @@ testRun(void)
// ***************************************************************************************************************************** // *****************************************************************************************************************************
if (testBegin("storageList()")) if (testBegin("storageList()"))
{ {
TEST_CREATE_NOPERM();
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
TEST_ERROR_FMT( TEST_ERROR_FMT(
storageListP(storageTest, strNew(BOGUS_STR), .errorOnMissing = true), PathOpenError, storageListP(storageTest, strNew(BOGUS_STR), .errorOnMissing = true), PathOpenError,
@ -241,6 +251,8 @@ testRun(void)
// ***************************************************************************************************************************** // *****************************************************************************************************************************
if (testBegin("storageMove()")) if (testBegin("storageMove()"))
{ {
TEST_CREATE_NOPERM();
String *sourceFile = strNewFmt("%s/source.txt", testPath()); String *sourceFile = strNewFmt("%s/source.txt", testPath());
String *destinationFile = strNewFmt("%s/sub/destination.txt", testPath()); String *destinationFile = strNewFmt("%s/sub/destination.txt", testPath());
@ -448,6 +460,8 @@ testRun(void)
// ***************************************************************************************************************************** // *****************************************************************************************************************************
if (testBegin("storagePathSync()")) if (testBegin("storagePathSync()"))
{ {
TEST_CREATE_NOPERM();
TEST_ERROR_FMT( TEST_ERROR_FMT(
storagePathSyncNP(storageTest, fileNoPerm), PathOpenError, storagePathSyncNP(storageTest, fileNoPerm), PathOpenError,
"unable to open '%s' for sync: [13] Permission denied", strPtr(fileNoPerm)); "unable to open '%s' for sync: [13] Permission denied", strPtr(fileNoPerm));
@ -492,6 +506,7 @@ testRun(void)
// ***************************************************************************************************************************** // *****************************************************************************************************************************
if (testBegin("storageNewWrite()")) if (testBegin("storageNewWrite()"))
{ {
TEST_CREATE_NOPERM();
StorageFileWrite *file = NULL; StorageFileWrite *file = NULL;
TEST_ASSIGN(file, storageNewWriteP(storageTest, fileNoPerm, .noAtomic = true), "new write file (defaults)"); TEST_ASSIGN(file, storageNewWriteP(storageTest, fileNoPerm, .noAtomic = true), "new write file (defaults)");
@ -581,6 +596,8 @@ testRun(void)
// ***************************************************************************************************************************** // *****************************************************************************************************************************
if (testBegin("storageRemove()")) if (testBegin("storageRemove()"))
{ {
TEST_CREATE_NOPERM();
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
TEST_RESULT_VOID(storageRemoveNP(storageTest, strNew("missing")), "remove missing file"); TEST_RESULT_VOID(storageRemoveNP(storageTest, strNew("missing")), "remove missing file");
TEST_ERROR_FMT( TEST_ERROR_FMT(