2018-01-17 15:52:00 -05:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Test Archive Push Command
|
|
|
|
***********************************************************************************************************************************/
|
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
|
|
|
|
testRun()
|
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
|
|
|
|
Storage *storageTest = storageNewP(strNew(testPath()), .write = true);
|
|
|
|
|
2018-01-17 15:52:00 -05:00
|
|
|
// *****************************************************************************************************************************
|
|
|
|
if (testBegin("cmdArchivePush()"))
|
|
|
|
{
|
|
|
|
StringList *argList = strLstNew();
|
|
|
|
strLstAddZ(argList, "pgbackrest");
|
|
|
|
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
|
|
|
|
|
|
|
TEST_ERROR(cmdArchivePush(), AssertError, "archive-push in C does not support synchronous mode");
|
|
|
|
|
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
|
|
|
|
lockAcquire(cfgOptionStr(cfgOptLockPath), cfgOptionStr(cfgOptStanza), cfgLockType(), 30, true);
|
|
|
|
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-04-23 17:26:27 -04:00
|
|
|
storagePutNP(storageNewWriteNP(storageSpool(), errorFile), bufNewStr(strNew("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-04-23 17:26:27 -04:00
|
|
|
storageNewWriteNP(storageSpool(), strNew(STORAGE_SPOOL_ARCHIVE_OUT "/000000010000000100000001.ok")),
|
2018-04-03 12:25:21 -04:00
|
|
|
bufNewStr(strNew("")));
|
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
|
|
|
|
|
|
|
storageRemoveP(storageSpool(), strNew(STORAGE_SPOOL_ARCHIVE_OUT "/000000010000000100000001.ok"), .errorOnMissing = true);
|
|
|
|
|
|
|
|
// 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(
|
|
|
|
lockAcquire(cfgOptionStr(cfgOptLockPath), cfgOptionStr(cfgOptStanza), cfgLockType(), 30, true), "acquire lock");
|
|
|
|
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
|
|
|
}
|