2018-01-17 15:52:00 -05:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Test Archive Push Command
|
|
|
|
***********************************************************************************************************************************/
|
2018-09-14 16:08:33 -04:00
|
|
|
#include "storage/driver/posix/storage.h"
|
|
|
|
|
2018-04-13 16:05:52 -04:00
|
|
|
#include "common/harnessConfig.h"
|
|
|
|
|
2018-01-17 15:52:00 -05:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Test Run
|
|
|
|
***********************************************************************************************************************************/
|
2018-01-31 18:22:25 -05:00
|
|
|
void
|
2018-08-03 19:19:14 -04:00
|
|
|
testRun(void)
|
2018-01-17 15:52:00 -05:00
|
|
|
{
|
2018-05-18 11:57:32 -04:00
|
|
|
FUNCTION_HARNESS_VOID();
|
|
|
|
|
2018-05-05 09:38:09 -04:00
|
|
|
// Create default storage object for testing
|
2018-09-14 16:08:33 -04:00
|
|
|
Storage *storageTest = storageDriverPosixInterface(
|
|
|
|
storageDriverPosixNew(strNew(testPath()), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL));
|
2018-05-05 09:38:09 -04:00
|
|
|
|
2018-01-17 15:52:00 -05:00
|
|
|
// *****************************************************************************************************************************
|
|
|
|
if (testBegin("cmdArchivePush()"))
|
|
|
|
{
|
|
|
|
StringList *argList = strLstNew();
|
2019-03-14 13:38:55 +04:00
|
|
|
strLstAddZ(argList, "pgbackrest-bogus");
|
2018-01-17 15:52:00 -05:00
|
|
|
strLstAddZ(argList, "--archive-timeout=1");
|
|
|
|
strLstAddZ(argList, "--stanza=db");
|
|
|
|
strLstAddZ(argList, "archive-push");
|
2018-07-20 18:51:42 -04:00
|
|
|
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
|
2018-01-17 15:52:00 -05:00
|
|
|
|
|
|
|
TEST_ERROR(cmdArchivePush(), ParamRequiredError, "WAL segment to push required");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
strLstAddZ(argList, "000000010000000100000001");
|
2018-07-20 18:51:42 -04:00
|
|
|
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
|
2018-01-17 15:52:00 -05:00
|
|
|
|
2019-03-14 13:38:55 +04:00
|
|
|
TEST_ERROR(cmdArchivePush(), OptionRequiredError , "===PERL-EMBED-ERROR===");
|
2018-01-17 15:52:00 -05:00
|
|
|
|
2018-04-12 20:42:26 -04:00
|
|
|
// Make sure the process times out when there is nothing to archive
|
2018-01-17 15:52:00 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2018-05-05 09:38:09 -04:00
|
|
|
storagePathCreateNP(storageTest, strNewFmt("%s/db/archive_status", testPath()));
|
|
|
|
|
2018-01-17 15:52:00 -05:00
|
|
|
strLstAdd(argList, strNewFmt("--spool-path=%s", testPath()));
|
|
|
|
strLstAddZ(argList, "--archive-async");
|
2018-05-05 09:38:09 -04:00
|
|
|
strLstAdd(argList, strNewFmt("--log-path=%s", testPath()));
|
|
|
|
strLstAdd(argList, strNewFmt("--log-level-file=debug"));
|
2018-04-12 20:42:26 -04:00
|
|
|
strLstAdd(argList, strNewFmt("--pg1-path=%s/db", testPath()));
|
2018-04-13 16:05:52 -04:00
|
|
|
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
|
2018-01-17 15:52:00 -05:00
|
|
|
|
2018-04-12 20:42:26 -04:00
|
|
|
TEST_ERROR(
|
|
|
|
cmdArchivePush(), ArchiveTimeoutError,
|
|
|
|
"unable to push WAL segment '000000010000000100000001' asynchronously after 1 second(s)");
|
2018-01-17 15:52:00 -05:00
|
|
|
|
2018-05-05 09:38:09 -04:00
|
|
|
// Wait for the lock to release
|
2018-11-08 08:37:57 -05:00
|
|
|
lockAcquire(cfgOptionStr(cfgOptLockPath), cfgOptionStr(cfgOptStanza), cfgLockType(), 30000, true);
|
2018-05-05 09:38:09 -04:00
|
|
|
lockRelease(true);
|
2018-01-17 15:52:00 -05:00
|
|
|
|
2018-02-14 17:19:54 -05:00
|
|
|
// Write out a bogus .error file to make sure it is ignored on the first loop
|
2018-01-17 15:52:00 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2018-05-05 09:38:09 -04:00
|
|
|
// Remove the archive status path so async will error and not overwrite the bogus error file
|
|
|
|
storagePathRemoveNP(storageTest, strNewFmt("%s/db/archive_status", testPath()));
|
2018-01-17 15:52:00 -05:00
|
|
|
|
2018-05-05 09:38:09 -04:00
|
|
|
String *errorFile = storagePathNP(storageSpool(), strNew(STORAGE_SPOOL_ARCHIVE_OUT "/000000010000000100000001.error"));
|
2018-09-26 18:46:52 +01:00
|
|
|
storagePutNP(storageNewWriteNP(storageSpoolWrite(), errorFile), bufNewZ("25\n" BOGUS_STR));
|
2018-01-17 15:52:00 -05:00
|
|
|
|
2018-02-14 17:19:54 -05:00
|
|
|
TEST_ERROR(cmdArchivePush(), AssertError, BOGUS_STR);
|
2018-01-17 15:52:00 -05:00
|
|
|
|
2018-05-05 09:38:09 -04:00
|
|
|
storageRemoveP(storageTest, errorFile, .errorOnMissing = true);
|
2018-01-17 15:52:00 -05:00
|
|
|
|
2018-02-14 17:19:54 -05:00
|
|
|
// Write out a valid ok file and test for success
|
2018-01-17 15:52:00 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2018-04-03 12:25:21 -04:00
|
|
|
storagePutNP(
|
2018-09-26 18:46:52 +01:00
|
|
|
storageNewWriteNP(storageSpoolWrite(), strNew(STORAGE_SPOOL_ARCHIVE_OUT "/000000010000000100000001.ok")), bufNew(0));
|
2018-01-17 15:52:00 -05:00
|
|
|
|
|
|
|
TEST_RESULT_VOID(cmdArchivePush(), "successful push");
|
2018-07-20 18:51:42 -04:00
|
|
|
harnessLogResult("P00 INFO: pushed WAL segment 000000010000000100000001 asynchronously");
|
2018-05-05 09:38:09 -04:00
|
|
|
|
2018-09-16 14:12:53 -04:00
|
|
|
storageRemoveP(
|
|
|
|
storageSpoolWrite(), strNew(STORAGE_SPOOL_ARCHIVE_OUT "/000000010000000100000001.ok"), .errorOnMissing = true);
|
2018-05-05 09:38:09 -04:00
|
|
|
|
|
|
|
// Make sure the process times out when there is nothing to archive and it can't get a lock. This test MUST go last since
|
|
|
|
// the lock is lost and cannot be closed by the main process.
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_RESULT_VOID(
|
2018-11-08 08:37:57 -05:00
|
|
|
lockAcquire(cfgOptionStr(cfgOptLockPath), cfgOptionStr(cfgOptStanza), cfgLockType(), 30000, true), "acquire lock");
|
2018-05-05 09:38:09 -04:00
|
|
|
TEST_RESULT_VOID(lockClear(true), "clear lock");
|
|
|
|
|
|
|
|
TEST_ERROR(
|
|
|
|
cmdArchivePush(), ArchiveTimeoutError,
|
|
|
|
"unable to push WAL segment '000000010000000100000001' asynchronously after 1 second(s)");
|
2018-01-17 15:52:00 -05:00
|
|
|
}
|
2018-05-18 11:57:32 -04:00
|
|
|
|
|
|
|
FUNCTION_HARNESS_RESULT_VOID();
|
2018-01-17 15:52:00 -05:00
|
|
|
}
|